Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/CommitFacility.java @ 586:73c20c648c1f
HgCommitCommand initial support
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 26 Apr 2013 18:38:41 +0200 |
parents | ca56a36c2eea |
children | 41218d84842a |
comparison
equal
deleted
inserted
replaced
585:b47ef0d2777b | 586:73c20c648c1f |
---|---|
26 import java.util.Map; | 26 import java.util.Map; |
27 import java.util.Set; | 27 import java.util.Set; |
28 import java.util.TreeMap; | 28 import java.util.TreeMap; |
29 import java.util.TreeSet; | 29 import java.util.TreeSet; |
30 | 30 |
31 import org.tmatesoft.hg.core.HgCommitCommand; | |
31 import org.tmatesoft.hg.core.HgRepositoryLockException; | 32 import org.tmatesoft.hg.core.HgRepositoryLockException; |
32 import org.tmatesoft.hg.core.Nodeid; | 33 import org.tmatesoft.hg.core.Nodeid; |
33 import org.tmatesoft.hg.internal.ByteArrayChannel; | 34 import org.tmatesoft.hg.internal.ByteArrayChannel; |
34 import org.tmatesoft.hg.internal.ChangelogEntryBuilder; | 35 import org.tmatesoft.hg.internal.ChangelogEntryBuilder; |
35 import org.tmatesoft.hg.internal.Experimental; | 36 import org.tmatesoft.hg.internal.Experimental; |
42 import org.tmatesoft.hg.util.Path; | 43 import org.tmatesoft.hg.util.Path; |
43 import org.tmatesoft.hg.util.LogFacility.Severity; | 44 import org.tmatesoft.hg.util.LogFacility.Severity; |
44 | 45 |
45 /** | 46 /** |
46 * WORK IN PROGRESS | 47 * WORK IN PROGRESS |
48 * Name: CommitObject, FutureCommit or PendingCommit | |
49 * Only public API now: {@link HgCommitCommand}. TEMPORARILY lives in the oth.repo public packages, until code interdependencies are resolved | |
47 * | 50 * |
48 * @author Artem Tikhomirov | 51 * @author Artem Tikhomirov |
49 * @author TMate Software Ltd. | 52 * @author TMate Software Ltd. |
50 */ | 53 */ |
51 @Experimental(reason="Work in progress") | 54 @Experimental(reason="Work in progress") |
52 public final class CommitFacility { | 55 public final class CommitFacility { |
53 private final HgRepository repo; | 56 private final HgRepository repo; |
54 private final int p1Commit, p2Commit; | 57 private final int p1Commit, p2Commit; |
55 private Map<Path, Pair<HgDataFile, ByteDataSupplier>> files = new LinkedHashMap<Path, Pair<HgDataFile, ByteDataSupplier>>(); | 58 private Map<Path, Pair<HgDataFile, ByteDataSupplier>> files = new LinkedHashMap<Path, Pair<HgDataFile, ByteDataSupplier>>(); |
56 private Set<Path> removals = new TreeSet<Path>(); | 59 private Set<Path> removals = new TreeSet<Path>(); |
57 private String branch; | 60 private String branch, user; |
58 | 61 |
59 public CommitFacility(HgRepository hgRepo, int parentCommit) { | 62 public CommitFacility(HgRepository hgRepo, int parentCommit) { |
60 this(hgRepo, parentCommit, NO_REVISION); | 63 this(hgRepo, parentCommit, NO_REVISION); |
61 } | 64 } |
62 | 65 |
86 removals.add(dataFile.getPath()); | 89 removals.add(dataFile.getPath()); |
87 } | 90 } |
88 | 91 |
89 public void branch(String branchName) { | 92 public void branch(String branchName) { |
90 branch = branchName; | 93 branch = branchName; |
94 } | |
95 | |
96 public void user(String userName) { | |
97 user = userName; | |
91 } | 98 } |
92 | 99 |
93 public Nodeid commit(String message) throws HgRepositoryLockException { | 100 public Nodeid commit(String message) throws HgRepositoryLockException { |
94 | 101 |
95 final HgChangelog clog = repo.getChangelog(); | 102 final HgChangelog clog = repo.getChangelog(); |
170 // | 177 // |
171 // Changelog | 178 // Changelog |
172 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder(); | 179 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder(); |
173 changelogBuilder.setModified(files.keySet()); | 180 changelogBuilder.setModified(files.keySet()); |
174 changelogBuilder.branch(branch == null ? HgRepository.DEFAULT_BRANCH_NAME : branch); | 181 changelogBuilder.branch(branch == null ? HgRepository.DEFAULT_BRANCH_NAME : branch); |
182 changelogBuilder.user(String.valueOf(user)); | |
175 byte[] clogContent = changelogBuilder.build(manifestRev, message); | 183 byte[] clogContent = changelogBuilder.build(manifestRev, message); |
176 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo.getSessionContext(), clog.content); | 184 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo.getSessionContext(), clog.content); |
177 Nodeid changesetRev = changelogWriter.addRevision(clogContent, clogRevisionIndex, p1Commit, p2Commit); | 185 Nodeid changesetRev = changelogWriter.addRevision(clogContent, clogRevisionIndex, p1Commit, p2Commit); |
178 // FIXME move fncache update to an external facility, along with dirstate update | 186 // FIXME move fncache update to an external facility, along with dirstate update |
179 if (!newlyAddedFiles.isEmpty() && repo.getImplHelper().fncacheInUse()) { | 187 if (!newlyAddedFiles.isEmpty() && repo.getImplHelper().fncacheInUse()) { |
208 } | 216 } |
209 */ | 217 */ |
210 | 218 |
211 // unlike DataAccess (which provides structured access), this one | 219 // unlike DataAccess (which provides structured access), this one |
212 // deals with a sequence of bytes, when there's no need in structure of the data | 220 // deals with a sequence of bytes, when there's no need in structure of the data |
221 // FIXME java.nio.ReadableByteChannel or ByteStream/ByteSequence(read, length, reset) | |
222 // SHALL be inline with util.ByteChannel, reading bytes from HgDataFile, preferably DataAccess#readBytes(BB) to match API, | |
223 // and a wrap for ByteVector | |
213 public interface ByteDataSupplier { // TODO look if can resolve DataAccess in HgCloneCommand visibility issue | 224 public interface ByteDataSupplier { // TODO look if can resolve DataAccess in HgCloneCommand visibility issue |
214 // FIXME needs lifecycle, e.g. for supplier that reads from WC | 225 // FIXME needs lifecycle, e.g. for supplier that reads from WC |
215 int read(ByteBuffer buf); | 226 int read(ByteBuffer buf); |
216 } | 227 } |
217 | 228 |