comparison src/org/tmatesoft/hg/core/HgStatusCommand.java @ 229:1ec6b327a6ac

Scope for status reworked: explicit files or a general matcher
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 31 May 2011 05:23:07 +0200
parents 41a778e3fd31
children 6d1804fe0ed7
comparison
equal deleted inserted replaced
228:fffe4f882248 229:1ec6b327a6ac
27 import org.tmatesoft.hg.repo.HgRepository; 27 import org.tmatesoft.hg.repo.HgRepository;
28 import org.tmatesoft.hg.repo.HgStatusCollector; 28 import org.tmatesoft.hg.repo.HgStatusCollector;
29 import org.tmatesoft.hg.repo.HgStatusInspector; 29 import org.tmatesoft.hg.repo.HgStatusInspector;
30 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; 30 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
31 import org.tmatesoft.hg.util.Path; 31 import org.tmatesoft.hg.util.Path;
32 import org.tmatesoft.hg.util.Path.Matcher;
33 32
34 /** 33 /**
35 * Command to obtain file status information, 'hg status' counterpart. 34 * Command to obtain file status information, 'hg status' counterpart.
36 * 35 *
37 * @author Artem Tikhomirov 36 * @author Artem Tikhomirov
39 */ 38 */
40 public class HgStatusCommand extends HgAbstractCommand<HgStatusCommand> { 39 public class HgStatusCommand extends HgAbstractCommand<HgStatusCommand> {
41 private final HgRepository repo; 40 private final HgRepository repo;
42 41
43 private int startRevision = TIP; 42 private int startRevision = TIP;
44 private int endRevision = WORKING_COPY; 43 private int endRevision = WORKING_COPY;
44 private Path.Matcher scope;
45 45
46 private final Mediator mediator = new Mediator(); 46 private final Mediator mediator = new Mediator();
47 47
48 public HgStatusCommand(HgRepository hgRepo) { 48 public HgStatusCommand(HgRepository hgRepo) {
49 repo = hgRepo; 49 repo = hgRepo;
144 * Limit status operation to certain sub-tree. 144 * Limit status operation to certain sub-tree.
145 * 145 *
146 * @param pathMatcher - matcher to use, pass <code>null/<code> to reset 146 * @param pathMatcher - matcher to use, pass <code>null/<code> to reset
147 * @return <code>this</code> for convenience 147 * @return <code>this</code> for convenience
148 */ 148 */
149 public HgStatusCommand match(Path.Matcher pathMatcher) { 149 public HgStatusCommand match(Path.Matcher scopeMatcher) {
150 mediator.matcher = pathMatcher; 150 scope = scopeMatcher;
151 return this; 151 return this;
152 } 152 }
153 153
154 public HgStatusCommand subrepo(boolean visit) { 154 public HgStatusCommand subrepo(boolean visit) {
155 throw HgRepository.notImplemented(); 155 throw HgRepository.notImplemented();
174 try { 174 try {
175 // XXX if I need a rough estimation (for ProgressMonitor) of number of work units, 175 // XXX if I need a rough estimation (for ProgressMonitor) of number of work units,
176 // I may use number of files in either rev1 or rev2 manifest edition 176 // I may use number of files in either rev1 or rev2 manifest edition
177 mediator.start(statusHandler, new ChangelogHelper(repo, startRevision)); 177 mediator.start(statusHandler, new ChangelogHelper(repo, startRevision));
178 if (endRevision == WORKING_COPY) { 178 if (endRevision == WORKING_COPY) {
179 HgWorkingCopyStatusCollector wcsc = new HgWorkingCopyStatusCollector(repo); 179 HgWorkingCopyStatusCollector wcsc = scope != null ? HgWorkingCopyStatusCollector.create(repo, scope) : new HgWorkingCopyStatusCollector(repo);
180 wcsc.setBaseRevisionCollector(sc); 180 wcsc.setBaseRevisionCollector(sc);
181 wcsc.walk(startRevision, mediator); 181 wcsc.walk(startRevision, mediator);
182 } else { 182 } else {
183 sc.setScope(scope); // explicitly set, even if null - would be handy once we reuse StatusCollector
183 if (startRevision == TIP) { 184 if (startRevision == TIP) {
184 sc.change(endRevision, mediator); 185 sc.change(endRevision, mediator);
185 } else { 186 } else {
186 sc.walk(startRevision, endRevision, mediator); 187 sc.walk(startRevision, endRevision, mediator);
187 } 188 }
202 boolean needUnknown; 203 boolean needUnknown;
203 boolean needMissing; 204 boolean needMissing;
204 boolean needClean; 205 boolean needClean;
205 boolean needIgnored; 206 boolean needIgnored;
206 boolean needCopies; 207 boolean needCopies;
207 Matcher matcher;
208 Handler handler; 208 Handler handler;
209 private ChangelogHelper logHelper; 209 private ChangelogHelper logHelper;
210 210
211 Mediator() { 211 Mediator() {
212 } 212 }
225 return handler != null; 225 return handler != null;
226 } 226 }
227 227
228 public void modified(Path fname) { 228 public void modified(Path fname) {
229 if (needModified) { 229 if (needModified) {
230 if (matcher == null || matcher.accept(fname)) { 230 handler.handleStatus(new HgStatus(Modified, fname, logHelper));
231 handler.handleStatus(new HgStatus(Modified, fname, logHelper));
232 }
233 } 231 }
234 } 232 }
235 public void added(Path fname) { 233 public void added(Path fname) {
236 if (needAdded) { 234 if (needAdded) {
237 if (matcher == null || matcher.accept(fname)) { 235 handler.handleStatus(new HgStatus(Added, fname, logHelper));
238 handler.handleStatus(new HgStatus(Added, fname, logHelper));
239 }
240 } 236 }
241 } 237 }
242 public void removed(Path fname) { 238 public void removed(Path fname) {
243 if (needRemoved) { 239 if (needRemoved) {
244 if (matcher == null || matcher.accept(fname)) { 240 handler.handleStatus(new HgStatus(Removed, fname, logHelper));
245 handler.handleStatus(new HgStatus(Removed, fname, logHelper));
246 }
247 } 241 }
248 } 242 }
249 public void copied(Path fnameOrigin, Path fnameAdded) { 243 public void copied(Path fnameOrigin, Path fnameAdded) {
250 if (needCopies) { 244 if (needCopies) {
251 if (matcher == null || matcher.accept(fnameAdded)) { 245 // FIXME in fact, merged files may report 'copied from' as well, correct status kind thus may differ from Added
252 // FIXME in fact, merged files may report 'copied from' as well, correct status kind thus may differ from Added 246 handler.handleStatus(new HgStatus(Added, fnameAdded, fnameOrigin, logHelper));
253 handler.handleStatus(new HgStatus(Added, fnameAdded, fnameOrigin, logHelper));
254 }
255 } 247 }
256 } 248 }
257 public void missing(Path fname) { 249 public void missing(Path fname) {
258 if (needMissing) { 250 if (needMissing) {
259 if (matcher == null || matcher.accept(fname)) { 251 handler.handleStatus(new HgStatus(Missing, fname, logHelper));
260 handler.handleStatus(new HgStatus(Missing, fname, logHelper));
261 }
262 } 252 }
263 } 253 }
264 public void unknown(Path fname) { 254 public void unknown(Path fname) {
265 if (needUnknown) { 255 if (needUnknown) {
266 if (matcher == null || matcher.accept(fname)) { 256 handler.handleStatus(new HgStatus(Unknown, fname, logHelper));
267 handler.handleStatus(new HgStatus(Unknown, fname, logHelper));
268 }
269 } 257 }
270 } 258 }
271 public void clean(Path fname) { 259 public void clean(Path fname) {
272 if (needClean) { 260 if (needClean) {
273 if (matcher == null || matcher.accept(fname)) { 261 handler.handleStatus(new HgStatus(Clean, fname, logHelper));
274 handler.handleStatus(new HgStatus(Clean, fname, logHelper));
275 }
276 } 262 }
277 } 263 }
278 public void ignored(Path fname) { 264 public void ignored(Path fname) {
279 if (needIgnored) { 265 if (needIgnored) {
280 if (matcher == null || matcher.accept(fname)) { 266 handler.handleStatus(new HgStatus(Ignored, fname, logHelper));
281 handler.handleStatus(new HgStatus(Ignored, fname, logHelper));
282 }
283 } 267 }
284 } 268 }
285 } 269 }
286 } 270 }