Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RepositoryComparator.java @ 215:41a778e3fd31
Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 17 May 2011 00:56:54 +0200 |
parents | 6a2481866491 |
children | 9fb50c04f03c |
comparison
equal
deleted
inserted
replaced
214:4252faa556cd | 215:41a778e3fd31 |
---|---|
29 import java.util.Map.Entry; | 29 import java.util.Map.Entry; |
30 import java.util.Set; | 30 import java.util.Set; |
31 | 31 |
32 import org.tmatesoft.hg.core.HgBadStateException; | 32 import org.tmatesoft.hg.core.HgBadStateException; |
33 import org.tmatesoft.hg.core.HgException; | 33 import org.tmatesoft.hg.core.HgException; |
34 import org.tmatesoft.hg.core.HgRemoteConnectionException; | |
34 import org.tmatesoft.hg.core.Nodeid; | 35 import org.tmatesoft.hg.core.Nodeid; |
35 import org.tmatesoft.hg.repo.HgChangelog; | 36 import org.tmatesoft.hg.repo.HgChangelog; |
36 import org.tmatesoft.hg.repo.HgRemoteRepository; | 37 import org.tmatesoft.hg.repo.HgRemoteRepository; |
37 import org.tmatesoft.hg.repo.HgRemoteRepository.Range; | 38 import org.tmatesoft.hg.repo.HgRemoteRepository.Range; |
38 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteBranch; | 39 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteBranch; |
55 public RepositoryComparator(HgChangelog.ParentWalker pwLocal, HgRemoteRepository hgRemote) { | 56 public RepositoryComparator(HgChangelog.ParentWalker pwLocal, HgRemoteRepository hgRemote) { |
56 localRepo = pwLocal; | 57 localRepo = pwLocal; |
57 remoteRepo = hgRemote; | 58 remoteRepo = hgRemote; |
58 } | 59 } |
59 | 60 |
60 public RepositoryComparator compare(Object context) throws HgException, CancelledException { | 61 public RepositoryComparator compare(ProgressSupport progressSupport, CancelSupport cancelSupport) throws HgRemoteConnectionException, CancelledException { |
61 ProgressSupport progressSupport = ProgressSupport.Factory.get(context); | |
62 CancelSupport cancelSupport = CancelSupport.Factory.get(context); | |
63 cancelSupport.checkCancelled(); | 62 cancelSupport.checkCancelled(); |
64 progressSupport.start(10); | 63 progressSupport.start(10); |
65 common = Collections.unmodifiableList(findCommonWithRemote()); | 64 common = Collections.unmodifiableList(findCommonWithRemote()); |
66 // sanity check | 65 // sanity check |
67 for (Nodeid n : common) { | 66 for (Nodeid n : common) { |
124 throw new HgBadStateException(String.format("Invalid index of common known revision: %d in total of %d", earliestRevision, 1+changelog.getLastRevision())); | 123 throw new HgBadStateException(String.format("Invalid index of common known revision: %d in total of %d", earliestRevision, 1+changelog.getLastRevision())); |
125 } | 124 } |
126 changelog.range(earliestRevision+1, changelog.getLastRevision(), inspector); | 125 changelog.range(earliestRevision+1, changelog.getLastRevision(), inspector); |
127 } | 126 } |
128 | 127 |
129 private List<Nodeid> findCommonWithRemote() throws HgException { | 128 private List<Nodeid> findCommonWithRemote() throws HgRemoteConnectionException { |
130 List<Nodeid> remoteHeads = remoteRepo.heads(); | 129 List<Nodeid> remoteHeads = remoteRepo.heads(); |
131 LinkedList<Nodeid> resultCommon = new LinkedList<Nodeid>(); // these remotes are known in local | 130 LinkedList<Nodeid> resultCommon = new LinkedList<Nodeid>(); // these remotes are known in local |
132 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common | 131 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common |
133 for (Nodeid rh : remoteHeads) { | 132 for (Nodeid rh : remoteHeads) { |
134 if (localRepo.knownNode(rh)) { | 133 if (localRepo.knownNode(rh)) { |
206 // TODO ensure unique elements in the list | 205 // TODO ensure unique elements in the list |
207 return resultCommon; | 206 return resultCommon; |
208 } | 207 } |
209 | 208 |
210 // somewhat similar to Outgoing.findCommonWithRemote() | 209 // somewhat similar to Outgoing.findCommonWithRemote() |
211 public List<BranchChain> calculateMissingBranches() throws HgException { | 210 public List<BranchChain> calculateMissingBranches() throws HgRemoteConnectionException { |
212 List<Nodeid> remoteHeads = remoteRepo.heads(); | 211 List<Nodeid> remoteHeads = remoteRepo.heads(); |
213 LinkedList<Nodeid> common = new LinkedList<Nodeid>(); // these remotes are known in local | 212 LinkedList<Nodeid> common = new LinkedList<Nodeid>(); // these remotes are known in local |
214 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common | 213 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common |
215 for (Nodeid rh : remoteHeads) { | 214 for (Nodeid rh : remoteHeads) { |
216 if (localRepo.knownNode(rh)) { | 215 if (localRepo.knownNode(rh)) { |