# HG changeset patch # User Artem Tikhomirov # Date 1355495989 -3600 # Node ID 122e0600799fea902f01550a3a2e3995c5ecacb2 # Parent 90093ee56c0d6f2bb3850c6d4ccf1fe8c9a71f77 Respect multiple joins/forks in a history of a single file diff -r 90093ee56c0d -r 122e0600799f cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Thu Dec 13 15:46:40 2012 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Fri Dec 14 15:39:49 2012 +0100 @@ -172,7 +172,8 @@ private void buildFileLog() throws Exception { final long start = System.nanoTime(); HgLogCommand cmd = new HgLogCommand(hgRepo); - cmd.file("cmdline/org/tmatesoft/hg/console/Remote.java", true); + cmd.file("file1b.txt", true); + final int[] count = new int[] { 0 }; cmd.execute(new HgChangesetTreeHandler() { public void treeElement(HgChangesetTreeHandler.TreeElement entry) { StringBuilder sb = new StringBuilder(); @@ -208,8 +209,10 @@ if (isJoin || isFork) { System.out.println(); } + count[0]++; } }); + System.out.println(count[0]); final long end = System.nanoTime(); System.out.printf("buildFileLog: %,d ms\n", (end-start)/1000); } diff -r 90093ee56c0d -r 122e0600799f src/org/tmatesoft/hg/core/HgLogCommand.java --- a/src/org/tmatesoft/hg/core/HgLogCommand.java Thu Dec 13 15:46:40 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgLogCommand.java Fri Dec 14 15:39:49 2012 +0100 @@ -24,6 +24,7 @@ import java.util.Calendar; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.LinkedList; @@ -541,6 +542,11 @@ queue.add(completeHistory[lastRevisionIndex]); do { HistoryNode withFileChange = queue.removeFirst(); + if (strippedHistoryList.contains(withFileChange)) { + // fork point for the change that was later merged (and we traced + // both lines of development by now. + continue; + } if (withFileChange.children != null) { withFileChange.children.retainAll(strippedHistoryList); } @@ -552,6 +558,12 @@ queue.addLast(withFileChange.parent2); } } while (!queue.isEmpty()); + Collections.sort(strippedHistoryList, new Comparator() { + + public int compare(HistoryNode o1, HistoryNode o2) { + return o1.changeset - o2.changeset; + } + }); completeHistory = null; commitRevisions = null; // collected values are no longer valid - shall @@ -666,6 +678,10 @@ child.parent1 = this; addChild(child); } + + public String toString() { + return String.format("", changeset, parent1 == null ? "-" : String.valueOf(parent1.changeset), parent2 == null ? "-" : String.valueOf(parent2.changeset)); + } } private class ElementImpl implements HgChangesetTreeHandler.TreeElement, HgChangelog.Inspector {