Mercurial > jhg
comparison src/org/tmatesoft/hg/core/StatusCommand.java @ 128:44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Feb 2011 20:13:41 +0100 |
parents | 2e395db595e2 |
children |
comparison
equal
deleted
inserted
replaced
127:2e395db595e2 | 128:44b97930570c |
---|---|
20 import static org.tmatesoft.hg.repo.HgRepository.*; | 20 import static org.tmatesoft.hg.repo.HgRepository.*; |
21 | 21 |
22 import java.util.ConcurrentModificationException; | 22 import java.util.ConcurrentModificationException; |
23 | 23 |
24 import org.tmatesoft.hg.core.Path.Matcher; | 24 import org.tmatesoft.hg.core.Path.Matcher; |
25 import org.tmatesoft.hg.internal.ChangelogHelper; | |
25 import org.tmatesoft.hg.repo.HgRepository; | 26 import org.tmatesoft.hg.repo.HgRepository; |
26 import org.tmatesoft.hg.repo.HgStatusCollector; | 27 import org.tmatesoft.hg.repo.HgStatusCollector; |
27 import org.tmatesoft.hg.repo.HgStatusInspector; | 28 import org.tmatesoft.hg.repo.HgStatusInspector; |
28 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; | 29 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; |
29 | 30 |
37 | 38 |
38 private int startRevision = TIP; | 39 private int startRevision = TIP; |
39 private int endRevision = WORKING_COPY; | 40 private int endRevision = WORKING_COPY; |
40 private boolean visitSubRepo = true; | 41 private boolean visitSubRepo = true; |
41 | 42 |
42 private Handler handler; | |
43 private final Mediator mediator = new Mediator(); | 43 private final Mediator mediator = new Mediator(); |
44 | 44 |
45 public StatusCommand(HgRepository hgRepo) { | 45 public StatusCommand(HgRepository hgRepo) { |
46 repo = hgRepo; | 46 repo = hgRepo; |
47 defaults(); | 47 defaults(); |
143 */ | 143 */ |
144 public void execute(Handler statusHandler) { | 144 public void execute(Handler statusHandler) { |
145 if (statusHandler == null) { | 145 if (statusHandler == null) { |
146 throw new IllegalArgumentException(); | 146 throw new IllegalArgumentException(); |
147 } | 147 } |
148 if (handler != null) { | 148 if (mediator.busy()) { |
149 throw new ConcurrentModificationException(); | 149 throw new ConcurrentModificationException(); |
150 } | 150 } |
151 handler = statusHandler; | |
152 HgStatusCollector sc = new HgStatusCollector(repo); // TODO from CommandContext | 151 HgStatusCollector sc = new HgStatusCollector(repo); // TODO from CommandContext |
153 // PathPool pathHelper = new PathPool(repo.getPathHelper()); // TODO from CommandContext | 152 // PathPool pathHelper = new PathPool(repo.getPathHelper()); // TODO from CommandContext |
154 try { | 153 try { |
155 // XXX if I need a rough estimation (for ProgressMonitor) of number of work units, | 154 // XXX if I need a rough estimation (for ProgressMonitor) of number of work units, |
156 // I may use number of files in either rev1 or rev2 manifest edition | 155 // I may use number of files in either rev1 or rev2 manifest edition |
157 mediator.start(); | 156 mediator.start(statusHandler, new ChangelogHelper(repo, startRevision)); |
158 if (endRevision == WORKING_COPY) { | 157 if (endRevision == WORKING_COPY) { |
159 HgWorkingCopyStatusCollector wcsc = new HgWorkingCopyStatusCollector(repo); | 158 HgWorkingCopyStatusCollector wcsc = new HgWorkingCopyStatusCollector(repo); |
160 wcsc.setBaseRevisionCollector(sc); | 159 wcsc.setBaseRevisionCollector(sc); |
161 wcsc.walk(startRevision, mediator); | 160 wcsc.walk(startRevision, mediator); |
162 } else { | 161 } else { |
166 sc.walk(startRevision, endRevision, mediator); | 165 sc.walk(startRevision, endRevision, mediator); |
167 } | 166 } |
168 } | 167 } |
169 } finally { | 168 } finally { |
170 mediator.done(); | 169 mediator.done(); |
171 handler = null; | |
172 } | 170 } |
173 } | 171 } |
174 | 172 |
175 public interface Handler { | 173 public interface Handler { |
176 void handleStatus(HgStatus s); | 174 void handleStatus(HgStatus s); |
184 boolean needMissing; | 182 boolean needMissing; |
185 boolean needClean; | 183 boolean needClean; |
186 boolean needIgnored; | 184 boolean needIgnored; |
187 boolean needCopies; | 185 boolean needCopies; |
188 Matcher matcher; | 186 Matcher matcher; |
187 Handler handler; | |
188 private ChangelogHelper logHelper; | |
189 | 189 |
190 Mediator() { | 190 Mediator() { |
191 } | 191 } |
192 | 192 |
193 public void start() { | 193 public void start(Handler h, ChangelogHelper changelogHelper) { |
194 | 194 handler = h; |
195 } | 195 logHelper = changelogHelper; |
196 } | |
197 | |
196 public void done() { | 198 public void done() { |
199 handler = null; | |
200 logHelper = null; | |
201 } | |
202 | |
203 public boolean busy() { | |
204 return handler != null; | |
197 } | 205 } |
198 | 206 |
199 public void modified(Path fname) { | 207 public void modified(Path fname) { |
200 if (needModified) { | 208 if (needModified) { |
201 if (matcher == null || matcher.accept(fname)) { | 209 if (matcher == null || matcher.accept(fname)) { |
202 handler.handleStatus(new HgStatus(Modified, fname)); | 210 handler.handleStatus(new HgStatus(Modified, fname, logHelper)); |
203 } | 211 } |
204 } | 212 } |
205 } | 213 } |
206 public void added(Path fname) { | 214 public void added(Path fname) { |
207 if (needAdded) { | 215 if (needAdded) { |
208 if (matcher == null || matcher.accept(fname)) { | 216 if (matcher == null || matcher.accept(fname)) { |
209 handler.handleStatus(new HgStatus(Added, fname)); | 217 handler.handleStatus(new HgStatus(Added, fname, logHelper)); |
210 } | 218 } |
211 } | 219 } |
212 } | 220 } |
213 public void removed(Path fname) { | 221 public void removed(Path fname) { |
214 if (needRemoved) { | 222 if (needRemoved) { |
215 if (matcher == null || matcher.accept(fname)) { | 223 if (matcher == null || matcher.accept(fname)) { |
216 handler.handleStatus(new HgStatus(Removed, fname)); | 224 handler.handleStatus(new HgStatus(Removed, fname, logHelper)); |
217 } | 225 } |
218 } | 226 } |
219 } | 227 } |
220 public void copied(Path fnameOrigin, Path fnameAdded) { | 228 public void copied(Path fnameOrigin, Path fnameAdded) { |
221 if (needCopies) { | 229 if (needCopies) { |
222 if (matcher == null || matcher.accept(fnameAdded)) { | 230 if (matcher == null || matcher.accept(fnameAdded)) { |
223 handler.handleStatus(new HgStatus(Added, fnameAdded, fnameOrigin)); | 231 handler.handleStatus(new HgStatus(Added, fnameAdded, fnameOrigin, logHelper)); |
224 } | 232 } |
225 } | 233 } |
226 } | 234 } |
227 public void missing(Path fname) { | 235 public void missing(Path fname) { |
228 if (needMissing) { | 236 if (needMissing) { |
229 if (matcher == null || matcher.accept(fname)) { | 237 if (matcher == null || matcher.accept(fname)) { |
230 handler.handleStatus(new HgStatus(Missing, fname)); | 238 handler.handleStatus(new HgStatus(Missing, fname, logHelper)); |
231 } | 239 } |
232 } | 240 } |
233 } | 241 } |
234 public void unknown(Path fname) { | 242 public void unknown(Path fname) { |
235 if (needUnknown) { | 243 if (needUnknown) { |
236 if (matcher == null || matcher.accept(fname)) { | 244 if (matcher == null || matcher.accept(fname)) { |
237 handler.handleStatus(new HgStatus(Unknown, fname)); | 245 handler.handleStatus(new HgStatus(Unknown, fname, logHelper)); |
238 } | 246 } |
239 } | 247 } |
240 } | 248 } |
241 public void clean(Path fname) { | 249 public void clean(Path fname) { |
242 if (needClean) { | 250 if (needClean) { |
243 if (matcher == null || matcher.accept(fname)) { | 251 if (matcher == null || matcher.accept(fname)) { |
244 handler.handleStatus(new HgStatus(Clean, fname)); | 252 handler.handleStatus(new HgStatus(Clean, fname, logHelper)); |
245 } | 253 } |
246 } | 254 } |
247 } | 255 } |
248 public void ignored(Path fname) { | 256 public void ignored(Path fname) { |
249 if (needIgnored) { | 257 if (needIgnored) { |
250 if (matcher == null || matcher.accept(fname)) { | 258 if (matcher == null || matcher.accept(fname)) { |
251 handler.handleStatus(new HgStatus(Ignored, fname)); | 259 handler.handleStatus(new HgStatus(Ignored, fname, logHelper)); |
252 } | 260 } |
253 } | 261 } |
254 } | 262 } |
255 } | 263 } |
256 } | 264 } |