comparison 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
comparison
equal deleted inserted replaced
641:2f33f102a8fa 659:a5cf64f2e7e4
242 return true; 242 return true;
243 } 243 }
244 } 244 }
245 return false; 245 return false;
246 } 246 }
247
248 /**
249 * Find out whether a given node is among descendants of another.
250 *
251 * @param root revision to check for being (grand-)*parent of a child
252 * @param wannaBeChild candidate descendant revision
253 * @return <code>true</code> if <code>wannaBeChild</code> is among children of <code>root</code>
254 */
255 public boolean isChild(Nodeid root, Nodeid wannaBeChild) {
256 int x = Arrays.binarySearch(sorted, root);
257 assertSortedIndex(x);
258 root = sorted[x]; // canonical instance
259 final int start = sorted2natural[x];
260 int y = Arrays.binarySearch(sorted, wannaBeChild);
261 if (y < 0) {
262 return false; // not found
263 }
264 wannaBeChild = sorted[y]; // canonicalize
265 final int end = sorted2natural[y];
266 if (end <= start) {
267 return false; // potential child was in repository earlier than root
268 }
269 HashSet<Nodeid> parents = new HashSet<Nodeid>();
270 parents.add(root);
271 for (int i = start + 1; i < end; i++) {
272 if (parents.contains(firstParent[i]) || parents.contains(secondParent[i])) {
273 parents.add(sequential[i]); // collect ancestors line
274 }
275 }
276 return parents.contains(firstParent[end]) || parents.contains(secondParent[end]);
277 }
247 } 278 }