comparison src/org/tmatesoft/hg/internal/RepositoryComparator.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 12a4f60ea972
comparison
equal deleted inserted replaced
652:cd77bf51b562 653:629a7370554c
36 import org.tmatesoft.hg.repo.HgInvalidStateException; 36 import org.tmatesoft.hg.repo.HgInvalidStateException;
37 import org.tmatesoft.hg.repo.HgParentChildMap; 37 import org.tmatesoft.hg.repo.HgParentChildMap;
38 import org.tmatesoft.hg.repo.HgRemoteRepository; 38 import org.tmatesoft.hg.repo.HgRemoteRepository;
39 import org.tmatesoft.hg.repo.HgRemoteRepository.Range; 39 import org.tmatesoft.hg.repo.HgRemoteRepository.Range;
40 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteBranch; 40 import org.tmatesoft.hg.repo.HgRemoteRepository.RemoteBranch;
41 import org.tmatesoft.hg.repo.HgRuntimeException;
42 import org.tmatesoft.hg.util.CancelSupport; 41 import org.tmatesoft.hg.util.CancelSupport;
43 import org.tmatesoft.hg.util.CancelledException; 42 import org.tmatesoft.hg.util.CancelledException;
44 import org.tmatesoft.hg.util.ProgressSupport; 43 import org.tmatesoft.hg.util.ProgressSupport;
45 44
46 /** 45 /**
111 RevisionSet outgoing = rsAncestors.subtract(rsAncestorsCommon).subtract(rsCommon); 110 RevisionSet outgoing = rsAncestors.subtract(rsAncestorsCommon).subtract(rsCommon);
112 return outgoing.union(rsCommonChildren).asList(); 111 return outgoing.union(rsCommonChildren).asList();
113 } 112 }
114 } 113 }
115 114
116 /**
117 * Similar to @link {@link #getLocalOnlyRevisions()}, use this one if you need access to changelog entry content, not
118 * only its revision number.
119 * @param inspector delegate to analyze changesets, shall not be <code>null</code>
120 */
121 public void visitLocalOnlyRevisions(HgChangelog.Inspector inspector) throws HgRuntimeException {
122 if (inspector == null) {
123 throw new IllegalArgumentException();
124 }
125 // one can use localRepo.childrenOf(getCommon()) and then iterate over nodeids, but there seems to be
126 // another approach to get all changes after common:
127 // find index of earliest revision, and report all that were later
128 final HgChangelog changelog = localRepo.getRepo().getChangelog();
129 int earliestRevision = Integer.MAX_VALUE;
130 List<Nodeid> commonKnown = getCommon();
131 for (Nodeid n : commonKnown) {
132 if (!localRepo.hasChildren(n)) {
133 // there might be (old) nodes, known both locally and remotely, with no children
134 // hence, we don't need to consider their local revision number
135 continue;
136 }
137 int lr = changelog.getRevisionIndex(n);
138 if (lr < earliestRevision) {
139 earliestRevision = lr;
140 }
141 }
142 if (earliestRevision == Integer.MAX_VALUE) {
143 // either there are no common nodes (known locally and at remote)
144 // or no local children found (local is up to date). In former case, perhaps I shall bit return silently,
145 // but check for possible wrong repo comparison (hs says 'repository is unrelated' if I try to
146 // check in/out for a repo that has no common nodes.
147 return;
148 }
149 if (earliestRevision < 0 || earliestRevision >= changelog.getLastRevision()) {
150 throw new HgInvalidStateException(String.format("Invalid index of common known revision: %d in total of %d", earliestRevision, 1+changelog.getLastRevision()));
151 }
152 changelog.range(earliestRevision+1, changelog.getLastRevision(), inspector);
153 }
154
155 private List<Nodeid> findCommonWithRemote() throws HgRemoteConnectionException { 115 private List<Nodeid> findCommonWithRemote() throws HgRemoteConnectionException {
156 remoteHeads = remoteRepo.heads(); 116 remoteHeads = remoteRepo.heads();
157 LinkedList<Nodeid> resultCommon = new LinkedList<Nodeid>(); // these remotes are known in local 117 LinkedList<Nodeid> resultCommon = new LinkedList<Nodeid>(); // these remotes are known in local
158 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common 118 LinkedList<Nodeid> toQuery = new LinkedList<Nodeid>(); // these need further queries to find common
159 for (Nodeid rh : remoteHeads) { 119 for (Nodeid rh : remoteHeads) {