# HG changeset patch # User Artem Tikhomirov # Date 1316862168 -7200 # Node ID 962f78aac342293589e75fd830138228dd8619af # Parent 3f40262153a4d9fd52fc3f4a0aeb6e7a622ef53f Branch with few children forked shall not ignore other children once one of them is processed diff -r 3f40262153a4 -r 962f78aac342 build.xml --- 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 @@ + diff -r 3f40262153a4 -r 962f78aac342 src/org/tmatesoft/hg/repo/HgBranches.java --- 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 branchLastSeen = new HashMap(); // revisions from the branch that have no children at all final HashMap> branchHeads = new HashMap>(); - // 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> branchHeadCandidates = new HashMap>(); HgChangelog.Inspector insp = new HgChangelog.Inspector() { @@ -194,8 +197,14 @@ } else { final List 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 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? diff -r 3f40262153a4 -r 962f78aac342 test/org/tmatesoft/hg/test/TestBranches.java --- 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);