# HG changeset patch # User Artem Tikhomirov # Date 1339006277 -7200 # Node ID 056f724bdc21bdd2d04f77d73cae12ee35b5c13e # Parent 9f0e6dfd417eb5939689345411d1770ed7a8401b Cache earliest phase root revision not to evaluate all the time diff -r 9f0e6dfd417e -r 056f724bdc21 src/org/tmatesoft/hg/internal/PhasesHelper.java --- a/src/org/tmatesoft/hg/internal/PhasesHelper.java Tue Jun 05 21:18:20 2012 +0200 +++ b/src/org/tmatesoft/hg/internal/PhasesHelper.java Wed Jun 06 20:11:17 2012 +0200 @@ -18,6 +18,7 @@ import static org.tmatesoft.hg.repo.HgPhase.Draft; import static org.tmatesoft.hg.repo.HgPhase.Secret; +import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; import java.io.BufferedReader; import java.io.File; @@ -51,6 +52,7 @@ private Boolean repoSupporsPhases; private List draftPhaseRoots; private List secretPhaseRoots; + private int[] earliestRevIndex = new int[HgPhase.values().length]; public PhasesHelper(HgRepository repo) { this(repo, null); @@ -59,6 +61,7 @@ public PhasesHelper(HgRepository repo, HgChangelog.ParentWalker pw) { hgRepo = repo; parentHelper = pw; + Arrays.fill(earliestRevIndex, BAD_REVISION); } public boolean isCapableOfPhases() throws HgInvalidControlFileException { @@ -98,9 +101,8 @@ } else { // no parent helper // search all descendants - int[] rootIndexes = toIndexes(roots); - Arrays.sort(rootIndexes); - if (rootIndexes[0] > csetRevIndex) { + int earliestRootRevIndex = getEarliestPhaseRevision(phase); + if (earliestRootRevIndex > csetRevIndex) { // this phase started later than our changeset was added, try another phase continue; } @@ -112,7 +114,7 @@ */ final HashSet parents2consider = new HashSet(roots); final boolean[] result = new boolean[] { false }; - hgRepo.getChangelog().walk(0/*rootIndexes[0]*/, csetRevIndex, new HgChangelog.ParentInspector() { + hgRepo.getChangelog().walk(0/*earlierstRootRevIndex*/, csetRevIndex, new HgChangelog.ParentInspector() { public void next(int revisionIndex, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) { boolean descendant = false; @@ -191,4 +193,15 @@ } return Collections.emptyList(); } + + private int getEarliestPhaseRevision(HgPhase phase) throws HgInvalidControlFileException { + int ordinal = phase.ordinal(); + if (earliestRevIndex[ordinal] == BAD_REVISION) { + int[] rootIndexes = toIndexes(getPhaseRoots(phase)); + Arrays.sort(rootIndexes); + // instead of MAX_VALUE may use clog.getLastRevision() + 1 + earliestRevIndex[ordinal] = rootIndexes.length == 0 ? Integer.MAX_VALUE : rootIndexes[0]; + } + return earliestRevIndex[ordinal]; + } }