diff src/org/tmatesoft/hg/repo/HgParentChildMap.java @ 659:a5cf64f2e7e4 smartgit-4.6

Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 05 Jul 2013 20:42:45 +0200
parents 6526d8adbc0f
children af5223b86dd3
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgParentChildMap.java	Tue Jun 11 16:31:42 2013 +0200
+++ b/src/org/tmatesoft/hg/repo/HgParentChildMap.java	Fri Jul 05 20:42:45 2013 +0200
@@ -244,4 +244,35 @@
 		}
 		return false;
 	}
+
+	/**
+     * Find out whether a given node is among descendants of another.
+     *
+     * @param root revision to check for being (grand-)*parent of a child
+     * @param wannaBeChild candidate descendant revision
+     * @return <code>true</code> if <code>wannaBeChild</code> is among children of <code>root</code>
+     */
+    public boolean isChild(Nodeid root, Nodeid wannaBeChild) {
+            int x = Arrays.binarySearch(sorted, root);
+            assertSortedIndex(x);
+            root = sorted[x]; // canonical instance
+            final int start = sorted2natural[x];
+            int y = Arrays.binarySearch(sorted, wannaBeChild);
+            if (y < 0) {
+                    return false; // not found
+            }
+            wannaBeChild = sorted[y]; // canonicalize
+            final int end = sorted2natural[y];
+            if (end <= start) {
+                    return false; // potential child was in repository earlier than root
+            }
+            HashSet<Nodeid> parents = new HashSet<Nodeid>();
+            parents.add(root);
+            for (int i = start + 1; i < end; i++) {
+                    if (parents.contains(firstParent[i]) || parents.contains(secondParent[i])) {
+                            parents.add(sequential[i]); // collect ancestors line
+                    }
+            }
+            return parents.contains(firstParent[end]) || parents.contains(secondParent[end]);
+    }
 }
\ No newline at end of file