}
}
}
}
for (RemoteBranch rb : checkUp2Head) {
Nodeid h = rb.head;
Nodeid r = rb.root;
int watchdog = 1000;
assert head2chain.containsKey(h);
BranchChain bc = head2chain.get(h);
assert bc != null : h.toString();
// if we know branch root locally, there could be no parent branch chain elements.
assert bc.p1 == null;
assert bc.p2 == null;
do {
List<Nodeid> between = remoteRepo.between(h, r);
if (between.isEmpty()) {
bc.branchRoot = r;
break;
} else {
Collections.reverse(between);
for (Nodeid n : between) {
if (localRepo.knownNode(n)) {
r = n;
} else {
h = n;
break;
}
}
Nodeid lastInBetween = between.get(between.size() - 1);
if (r.equals(lastInBetween)) {
bc.branchRoot = r;
break;
} else if (h.equals(lastInBetween)) { // the only chance for current head pointer to point to the sequence tail
// is when r is second from the between list end (iow, head,1,[2],4,8...,root)