Mercurial > hg4j
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/PhasesHelper.java Mon Jul 01 21:19:53 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/PhasesHelper.java Tue Jul 02 23:21:16 2013 +0200 @@ -36,6 +36,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgInvalidControlFileException; +import org.tmatesoft.hg.repo.HgInvalidStateException; import org.tmatesoft.hg.repo.HgParentChildMap; import org.tmatesoft.hg.repo.HgPhase; import org.tmatesoft.hg.repo.HgRepository; @@ -174,6 +175,33 @@ } } + public void newCommitNode(Nodeid newChangeset, HgPhase newCommitPhase) throws HgRuntimeException { + final int riCset = repo.getRepo().getChangelog().getRevisionIndex(newChangeset); + HgPhase ph = getPhase(riCset, newChangeset); + if (ph.compareTo(newCommitPhase) >= 0) { + // present phase is more secret than the desired one + return; + } + // newCommitPhase can't be public here, condition above would be satisfied + assert newCommitPhase != HgPhase.Public; + // ph is e.g public when newCommitPhase is draft + // or is draft when desired phase is secret + final RevisionSet rs = allOf(newCommitPhase).union(new RevisionSet(Collections.singleton(newChangeset))); + final RevisionSet newRoots; + if (parentHelper != null) { + newRoots = rs.roots(parentHelper); + } else { + newRoots = rs.roots(repo.getRepo()); + } + if (newCommitPhase == HgPhase.Draft) { + updateRoots(newRoots.asList(), secretPhaseRoots); + } else if (newCommitPhase == HgPhase.Secret) { + updateRoots(draftPhaseRoots, newRoots.asList()); + } else { + throw new HgInvalidStateException(String.format("Unexpected phase %s for new commits", newCommitPhase)); + } + } + /** * For a given phase, collect all revisions with phase that is the same or more private (i.e. for Draft, returns Draft+Secret) * The reason is not a nice API intention (which is awful, indeed), but an ease of implementation