comparison src/org/tmatesoft/hg/repo/HgParentChildMap.java @ 653:629a7370554c

Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 03 Jul 2013 14:38:30 +0200
parents cd77bf51b562
children a937e63b6e02
comparison
equal deleted inserted replaced
652:cd77bf51b562 653:629a7370554c
110 sequential = new Nodeid[revisionCount]; 110 sequential = new Nodeid[revisionCount];
111 sorted = new Nodeid[revisionCount]; 111 sorted = new Nodeid[revisionCount];
112 heads = new BitSet(revisionCount); 112 heads = new BitSet(revisionCount);
113 revlog.indexWalk(0, TIP, this); 113 revlog.indexWalk(0, TIP, this);
114 Arrays.sort(sorted); 114 Arrays.sort(sorted);
115 // FIXME use ArrayHelper instead
115 sorted2natural = new int[revisionCount]; 116 sorted2natural = new int[revisionCount];
116 for (int i = 0; i < revisionCount; i++) { 117 for (int i = 0; i < revisionCount; i++) {
117 Nodeid n = sequential[i]; 118 Nodeid n = sequential[i];
118 int x = Arrays.binarySearch(sorted, n); 119 int x = Arrays.binarySearch(sorted, n);
119 assertSortedIndex(x); 120 assertSortedIndex(x);
216 217
217 /** 218 /**
218 * @return revisions that have supplied revision as their immediate parent 219 * @return revisions that have supplied revision as their immediate parent
219 */ 220 */
220 public List<Nodeid> directChildren(Nodeid nid) { 221 public List<Nodeid> directChildren(Nodeid nid) {
221 LinkedList<Nodeid> result = new LinkedList<Nodeid>();
222 int x = Arrays.binarySearch(sorted, nid); 222 int x = Arrays.binarySearch(sorted, nid);
223 assertSortedIndex(x); 223 assertSortedIndex(x);
224 nid = sorted[x]; // canonical instance 224 nid = sorted[x]; // canonical instance
225 int start = sorted2natural[x]; 225 int start = sorted2natural[x];
226 if (!hasChildren(start)) {
227 return Collections.emptyList();
228 }
229 LinkedList<Nodeid> result = new LinkedList<Nodeid>();
226 for (int i = start + 1; i < sequential.length; i++) { 230 for (int i = start + 1; i < sequential.length; i++) {
227 if (nid == firstParent[i] || nid == secondParent[i]) { 231 if (nid == firstParent[i] || nid == secondParent[i]) {
228 result.add(sequential[i]); 232 result.add(sequential[i]);
229 } 233 }
230 } 234 }
289 public Collection<Nodeid> heads() { 293 public Collection<Nodeid> heads() {
290 ArrayList<Nodeid> result = new ArrayList<Nodeid>(); 294 ArrayList<Nodeid> result = new ArrayList<Nodeid>();
291 int index = 0; 295 int index = 0;
292 do { 296 do {
293 index = heads.nextClearBit(index); 297 index = heads.nextClearBit(index);
298 // nextClearBit(length-1) gives length when bit is set,
299 // however, last revision can't be a parent of any other, and
300 // the last bit would be always 0, and no AIOOBE
294 result.add(sequential[index]); 301 result.add(sequential[index]);
295 index++; 302 index++;
296 } while (index < sequential.length); 303 } while (index < sequential.length);
297 return result; 304 return result;
298 } 305 }