Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/PhasesHelper.java @ 652:cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 02 Jul 2013 23:21:16 +0200 |
| parents | 3b275cc2d2aa |
| children | 12a4f60ea972 |
comparison
equal
deleted
inserted
replaced
| 651:6e98d34eaca8 | 652:cd77bf51b562 |
|---|---|
| 34 import org.tmatesoft.hg.core.HgChangeset; | 34 import org.tmatesoft.hg.core.HgChangeset; |
| 35 import org.tmatesoft.hg.core.HgIOException; | 35 import org.tmatesoft.hg.core.HgIOException; |
| 36 import org.tmatesoft.hg.core.Nodeid; | 36 import org.tmatesoft.hg.core.Nodeid; |
| 37 import org.tmatesoft.hg.repo.HgChangelog; | 37 import org.tmatesoft.hg.repo.HgChangelog; |
| 38 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 38 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
| 39 import org.tmatesoft.hg.repo.HgInvalidStateException; | |
| 39 import org.tmatesoft.hg.repo.HgParentChildMap; | 40 import org.tmatesoft.hg.repo.HgParentChildMap; |
| 40 import org.tmatesoft.hg.repo.HgPhase; | 41 import org.tmatesoft.hg.repo.HgPhase; |
| 41 import org.tmatesoft.hg.repo.HgRepository; | 42 import org.tmatesoft.hg.repo.HgRepository; |
| 42 import org.tmatesoft.hg.repo.HgRuntimeException; | 43 import org.tmatesoft.hg.repo.HgRuntimeException; |
| 43 | 44 |
| 172 } finally { | 173 } finally { |
| 173 new FileUtils(repo.getLog()).closeQuietly(fw); | 174 new FileUtils(repo.getLog()).closeQuietly(fw); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 178 public void newCommitNode(Nodeid newChangeset, HgPhase newCommitPhase) throws HgRuntimeException { | |
| 179 final int riCset = repo.getRepo().getChangelog().getRevisionIndex(newChangeset); | |
| 180 HgPhase ph = getPhase(riCset, newChangeset); | |
| 181 if (ph.compareTo(newCommitPhase) >= 0) { | |
| 182 // present phase is more secret than the desired one | |
| 183 return; | |
| 184 } | |
| 185 // newCommitPhase can't be public here, condition above would be satisfied | |
| 186 assert newCommitPhase != HgPhase.Public; | |
| 187 // ph is e.g public when newCommitPhase is draft | |
| 188 // or is draft when desired phase is secret | |
| 189 final RevisionSet rs = allOf(newCommitPhase).union(new RevisionSet(Collections.singleton(newChangeset))); | |
| 190 final RevisionSet newRoots; | |
| 191 if (parentHelper != null) { | |
| 192 newRoots = rs.roots(parentHelper); | |
| 193 } else { | |
| 194 newRoots = rs.roots(repo.getRepo()); | |
| 195 } | |
| 196 if (newCommitPhase == HgPhase.Draft) { | |
| 197 updateRoots(newRoots.asList(), secretPhaseRoots); | |
| 198 } else if (newCommitPhase == HgPhase.Secret) { | |
| 199 updateRoots(draftPhaseRoots, newRoots.asList()); | |
| 200 } else { | |
| 201 throw new HgInvalidStateException(String.format("Unexpected phase %s for new commits", newCommitPhase)); | |
| 202 } | |
| 203 } | |
| 204 | |
| 177 /** | 205 /** |
| 178 * For a given phase, collect all revisions with phase that is the same or more private (i.e. for Draft, returns Draft+Secret) | 206 * For a given phase, collect all revisions with phase that is the same or more private (i.e. for Draft, returns Draft+Secret) |
| 179 * The reason is not a nice API intention (which is awful, indeed), but an ease of implementation | 207 * The reason is not a nice API intention (which is awful, indeed), but an ease of implementation |
| 180 */ | 208 */ |
| 181 private RevisionSet allOf(HgPhase phase) { | 209 private RevisionSet allOf(HgPhase phase) { |
