Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgIncomingCommand.java @ 202:706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 26 Apr 2011 02:50:06 +0200 |
parents | c9b305df0b89 |
children | ffc5f6d59f7e |
comparison
equal
deleted
inserted
replaced
201:a736f42ed75b | 202:706bcc7cfee4 |
---|---|
16 */ | 16 */ |
17 package org.tmatesoft.hg.core; | 17 package org.tmatesoft.hg.core; |
18 | 18 |
19 import java.io.IOException; | 19 import java.io.IOException; |
20 import java.util.ArrayList; | 20 import java.util.ArrayList; |
21 import java.util.HashSet; | |
22 import java.util.Iterator; | |
21 import java.util.LinkedHashSet; | 23 import java.util.LinkedHashSet; |
22 import java.util.LinkedList; | 24 import java.util.LinkedList; |
23 import java.util.List; | 25 import java.util.List; |
24 import java.util.Set; | 26 import java.util.Set; |
25 import java.util.TreeSet; | 27 import java.util.TreeSet; |
41 */ | 43 */ |
42 public class HgIncomingCommand { | 44 public class HgIncomingCommand { |
43 | 45 |
44 private final HgRepository localRepo; | 46 private final HgRepository localRepo; |
45 private HgRemoteRepository remoteRepo; | 47 private HgRemoteRepository remoteRepo; |
48 @SuppressWarnings("unused") | |
46 private boolean includeSubrepo; | 49 private boolean includeSubrepo; |
47 private RepositoryComparator comparator; | 50 private RepositoryComparator comparator; |
48 private List<BranchChain> missingBranches; | 51 private List<BranchChain> missingBranches; |
49 private HgChangelog.ParentWalker parentHelper; | 52 private HgChangelog.ParentWalker parentHelper; |
50 private Set<String> branches; | 53 private Set<String> branches; |
103 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException { | 106 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException { |
104 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>(); | 107 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>(); |
105 RepositoryComparator repoCompare = getComparator(context); | 108 RepositoryComparator repoCompare = getComparator(context); |
106 for (BranchChain bc : getMissingBranches(context)) { | 109 for (BranchChain bc : getMissingBranches(context)) { |
107 List<Nodeid> missing = repoCompare.visitBranches(bc); | 110 List<Nodeid> missing = repoCompare.visitBranches(bc); |
108 assert bc.branchRoot.equals(missing.get(0)); | 111 HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant |
109 missing.remove(0); | 112 repoCompare.collectKnownRoots(bc, common); |
113 // missing could only start with common elements. Once non-common, rest is just distinct branch revision trails. | |
114 for (Iterator<Nodeid> it = missing.iterator(); it.hasNext() && common.contains(it.next()); it.remove()) ; | |
110 result.addAll(missing); | 115 result.addAll(missing); |
111 } | 116 } |
112 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(result); | 117 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(result); |
113 return rv; | 118 return rv; |
114 } | 119 } |
122 public void executeFull(final HgLogCommand.Handler handler) throws HgException, CancelledException { | 127 public void executeFull(final HgLogCommand.Handler handler) throws HgException, CancelledException { |
123 if (handler == null) { | 128 if (handler == null) { |
124 throw new IllegalArgumentException("Delegate can't be null"); | 129 throw new IllegalArgumentException("Delegate can't be null"); |
125 } | 130 } |
126 final List<Nodeid> common = getCommon(handler); | 131 final List<Nodeid> common = getCommon(handler); |
127 HgBundle changegroup = remoteRepo.getChanges(new LinkedList<Nodeid>(common)); | 132 HgBundle changegroup = remoteRepo.getChanges(common); |
128 try { | 133 try { |
129 changegroup.changes(localRepo, new HgChangelog.Inspector() { | 134 changegroup.changes(localRepo, new HgChangelog.Inspector() { |
130 private int localIndex; | 135 private int localIndex = -1; // in case we start with empty repo and localIndex would not get initialized in regular way |
131 private final HgChangelog.ParentWalker parentHelper; | 136 private final HgChangelog.ParentWalker parentHelper; |
132 private final ChangesetTransformer transformer; | 137 private final ChangesetTransformer transformer; |
133 private final HgChangelog changelog; | 138 private final HgChangelog changelog; |
134 | 139 |
135 { | 140 { |
159 if (remoteRepo == null) { | 164 if (remoteRepo == null) { |
160 throw new HgBadArgumentException("Shall specify remote repository to compare against", null); | 165 throw new HgBadArgumentException("Shall specify remote repository to compare against", null); |
161 } | 166 } |
162 if (comparator == null) { | 167 if (comparator == null) { |
163 comparator = new RepositoryComparator(getParentHelper(), remoteRepo); | 168 comparator = new RepositoryComparator(getParentHelper(), remoteRepo); |
164 comparator.compare(context); | 169 // comparator.compare(context); // XXX meanwhile we use distinct path to calculate common |
165 } | 170 } |
166 return comparator; | 171 return comparator; |
167 } | 172 } |
168 | 173 |
169 private HgChangelog.ParentWalker getParentHelper() { | 174 private HgChangelog.ParentWalker getParentHelper() { |
180 } | 185 } |
181 return missingBranches; | 186 return missingBranches; |
182 } | 187 } |
183 | 188 |
184 private List<Nodeid> getCommon(Object context) throws HgException, CancelledException { | 189 private List<Nodeid> getCommon(Object context) throws HgException, CancelledException { |
190 // return getComparator(context).getCommon(); | |
185 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); | 191 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); |
186 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches | 192 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches |
187 // once I refactor latter, common shall be taken from repoCompare. | 193 // once I refactor latter, common shall be taken from repoCompare. |
194 RepositoryComparator repoCompare = getComparator(context); | |
188 for (BranchChain bc : getMissingBranches(context)) { | 195 for (BranchChain bc : getMissingBranches(context)) { |
189 common.add(bc.branchRoot); | 196 repoCompare.collectKnownRoots(bc, common); |
190 } | 197 } |
191 return new LinkedList<Nodeid>(common); | 198 return new LinkedList<Nodeid>(common); |
192 } | 199 } |
193 } | 200 } |