Mercurial > jhg
changeset 309:962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 24 Sep 2011 13:02:48 +0200 |
parents | 3f40262153a4 |
children | 237de162be28 |
files | build.xml src/org/tmatesoft/hg/repo/HgBranches.java test/org/tmatesoft/hg/test/TestBranches.java |
diffstat | 3 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/build.xml Sat Sep 24 07:29:05 2011 +0200 +++ b/build.xml Sat Sep 24 13:02:48 2011 +0200 @@ -88,6 +88,7 @@ <test name="org.tmatesoft.hg.test.TestStorePath" /> <test name="org.tmatesoft.hg.test.TestIgnore" /> <test name="org.tmatesoft.hg.test.TestDirstate" /> + <test name="org.tmatesoft.hg.test.TestBranches" /> <test name="org.tmatesoft.hg.test.TestByteChannel" /> <test name="org.tmatesoft.hg.test.TestClone" /> <test name="org.tmatesoft.hg.test.TestIncoming" />
--- a/src/org/tmatesoft/hg/repo/HgBranches.java Sat Sep 24 07:29:05 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgBranches.java Sat Sep 24 13:02:48 2011 +0200 @@ -181,7 +181,10 @@ final HashMap<String, Nodeid> branchLastSeen = new HashMap<String, Nodeid>(); // revisions from the branch that have no children at all final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>(); - // revisions that are immediate children of a node from a given branch + // revisions that are immediate children of a node from a given branch + // after iteration, there are some revisions left in this map (children of a branch last revision + // that doesn't belong to the branch. No use of this now, perhaps can deduce isInactive (e.g.those + // branches that have non-empty candidates are inactive if all their heads are roots for those left) final HashMap<String, List<Nodeid>> branchHeadCandidates = new HashMap<String, List<Nodeid>>(); HgChangelog.Inspector insp = new HgChangelog.Inspector() { @@ -194,8 +197,14 @@ } else { final List<Nodeid> headCandidates = branchHeadCandidates.get(branchName); if (headCandidates.remove(nodeid)) { - // no need to keep parent, as we found at least 1 child thereof to be at the same branch - branchLastSeen.remove(branchName); + // likely we don't need to keep parent anymore, as we found at least 1 child thereof to be at the same branch + // however, it's possible the child we found is a result of an earlier fork, and revision in the + // branchLastSeen is 'parallel' head, which needs to be kept + Nodeid lastSeenInBranch = branchLastSeen.get(branchName); + // check if current revision is on descendant line. Seems direct parents check is enough + if (pw.safeFirstParent(nodeid).equals(lastSeenInBranch) || pw.safeSecondParent(nodeid).equals(lastSeenInBranch)) { + branchLastSeen.remove(branchName); + } } } List<Nodeid> immediateChildren = pw.directChildren(nodeid); @@ -215,11 +224,6 @@ } }; repo.getChangelog().range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp); -// System.out.println("HEAD CANDIDATES>>>"); -// for (String bn : branchHeadCandidates.keySet()) { -// System.out.println(bn + ":" + branchHeadCandidates.get(bn).toString()); -// } -// System.out.println("HEAD CANDIDATES<<<"); // those last seen revisions from the branch that had no children from the same branch are heads. for (String bn : branchLastSeen.keySet()) { // these are inactive branches? - there were children, but not from the same branch?
--- a/test/org/tmatesoft/hg/test/TestBranches.java Sat Sep 24 07:29:05 2011 +0200 +++ b/test/org/tmatesoft/hg/test/TestBranches.java Sat Sep 24 13:02:48 2011 +0200 @@ -59,10 +59,9 @@ BranchInfo b4 = branches.getBranch("branch4"); assertNotNull(b4); assertFalse(b4.isClosed()); -// assertEquals(2, b4.getHeads().size()); + assertEquals(2, b4.getHeads().size()); assertEquals("fceabd402f0193fb30605aed0ee3a9d5feb99f60", b4.getHeads().get(0).toString()); - // FIXME second branch is not present when HgBranches builds cache itself!!! -// assertEquals("892b6a504be7835f1748ba632fe15a9389d4479b", b4.getHeads().get(1).toString()); + assertEquals("892b6a504be7835f1748ba632fe15a9389d4479b", b4.getHeads().get(1).toString()); // BranchInfo b5 = branches.getBranch("branch5"); assertNotNull(b5);