Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RepositoryComparator.java @ 698:822f3a83ff57
in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 21:18:33 +0200 |
parents | 12a4f60ea972 |
children |
comparison
equal
deleted
inserted
replaced
697:24f4efedc9d5 | 698:822f3a83ff57 |
---|---|
21 import java.util.ArrayList; | 21 import java.util.ArrayList; |
22 import java.util.Arrays; | 22 import java.util.Arrays; |
23 import java.util.Collections; | 23 import java.util.Collections; |
24 import java.util.HashMap; | 24 import java.util.HashMap; |
25 import java.util.HashSet; | 25 import java.util.HashSet; |
26 import java.util.LinkedHashSet; | |
26 import java.util.LinkedList; | 27 import java.util.LinkedList; |
27 import java.util.List; | 28 import java.util.List; |
28 import java.util.ListIterator; | 29 import java.util.ListIterator; |
29 import java.util.Map; | 30 import java.util.Map; |
30 import java.util.Map.Entry; | 31 import java.util.Map.Entry; |
199 | 200 |
200 // somewhat similar to Outgoing.findCommonWithRemote() | 201 // somewhat similar to Outgoing.findCommonWithRemote() |
201 public List<BranchChain> calculateMissingBranches() throws HgRemoteConnectionException { | 202 public List<BranchChain> calculateMissingBranches() throws HgRemoteConnectionException { |
202 List<Nodeid> remoteHeads = remoteRepo.heads(); | 203 List<Nodeid> remoteHeads = remoteRepo.heads(); |
203 LinkedList<Nodeid> common = new LinkedList<Nodeid>(); // these remotes are known in local | 204 LinkedList<Nodeid> common = new LinkedList<Nodeid>(); // these remotes are known in local |
204 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common | 205 LinkedHashSet<Nodeid> toQuery = new LinkedHashSet<Nodeid>(); // these need further queries to find common |
205 for (Nodeid rh : remoteHeads) { | 206 for (Nodeid rh : remoteHeads) { |
206 if (localRepo.knownNode(rh)) { | 207 if (localRepo.knownNode(rh)) { |
207 common.add(rh); | 208 common.add(rh); |
208 } else { | 209 } else { |
209 toQuery.add(rh); | 210 toQuery.add(rh); |
216 // detailed comments are in Outgoing.findCommonWithRemote | 217 // detailed comments are in Outgoing.findCommonWithRemote |
217 LinkedList<RemoteBranch> checkUp2Head = new LinkedList<RemoteBranch>(); | 218 LinkedList<RemoteBranch> checkUp2Head = new LinkedList<RemoteBranch>(); |
218 // records relation between branch head and its parent branch, if any | 219 // records relation between branch head and its parent branch, if any |
219 HashMap<Nodeid, BranchChain> head2chain = new HashMap<Nodeid, BranchChain>(); | 220 HashMap<Nodeid, BranchChain> head2chain = new HashMap<Nodeid, BranchChain>(); |
220 while (!toQuery.isEmpty()) { | 221 while (!toQuery.isEmpty()) { |
221 List<RemoteBranch> remoteBranches = remoteRepo.branches(toQuery); //head, root, first parent, second parent | 222 List<RemoteBranch> remoteBranches = remoteRepo.branches(new ArrayList<Nodeid>(toQuery)); //head, root, first parent, second parent |
222 toQuery.clear(); | 223 toQuery.clear(); |
223 while(!remoteBranches.isEmpty()) { | 224 while(!remoteBranches.isEmpty()) { |
224 RemoteBranch rb = remoteBranches.remove(0); | 225 RemoteBranch rb = remoteBranches.remove(0); |
225 BranchChain chainElement = head2chain.get(rb.head); | 226 BranchChain chainElement = head2chain.get(rb.head); |
226 if (chainElement == null) { | 227 if (chainElement == null) { |
238 // dig deeper in the history, if necessary | 239 // dig deeper in the history, if necessary |
239 boolean hasP1 = !rb.p1.isNull(), hasP2 = !rb.p2.isNull(); | 240 boolean hasP1 = !rb.p1.isNull(), hasP2 = !rb.p2.isNull(); |
240 if (hasP1 && !localRepo.knownNode(rb.p1)) { | 241 if (hasP1 && !localRepo.knownNode(rb.p1)) { |
241 toQuery.add(rb.p1); | 242 toQuery.add(rb.p1); |
242 // we might have seen parent node already, and recorded it as a branch chain | 243 // we might have seen parent node already, and recorded it as a branch chain |
243 // we shall reuse existing BC to get it completely initializer (head2chain map | 244 // we shall reuse existing BC to get it completely initialized (head2chain map |
244 // on second put with the same key would leave first BC uninitialized. | 245 // on second put with the same key would leave first BC uninitialized. |
245 | 246 |
246 // It seems there's no reason to be affraid (XXX although shall double-check) | 247 // It seems there's no reason to be afraid (XXX although shall double-check) |
247 // that BC's chain would get corrupt (its p1 and p2 fields assigned twice with different values) | 248 // that BC's chain would get corrupt (its p1 and p2 fields assigned twice with different values) |
248 // as parents are always the same (and likely, BC that is common would be the last unknown) | 249 // as parents are always the same (and likely, BC that is common would be the last unknown) |
249 BranchChain bc = head2chain.get(rb.p1); | 250 BranchChain bc = head2chain.get(rb.p1); |
250 if (bc == null) { | 251 if (bc == null) { |
251 head2chain.put(rb.p1, bc = new BranchChain(rb.p1)); | 252 head2chain.put(rb.p1, bc = new BranchChain(rb.p1)); |
350 return p1 == p2 && p1 != null && p1.branchHead == p1.branchRoot && p1.branchHead.isNull(); | 351 return p1 == p2 && p1 != null && p1.branchHead == p1.branchRoot && p1.branchHead.isNull(); |
351 } | 352 } |
352 | 353 |
353 @Override | 354 @Override |
354 public String toString() { | 355 public String toString() { |
355 return String.format("BranchChain [%s, %s]", branchRoot, branchHead); | 356 return String.format("BranchChain [root:%s, head:%s]", branchRoot, branchHead); |
356 } | 357 } |
357 | 358 |
358 void dump() { | 359 void dump() { |
359 System.out.println(toString()); | 360 System.out.println(toString()); |
360 internalDump(" "); | 361 internalDump(" "); |