Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgStatusCommand.java @ 582:90df078d6418
Delegate cancel to original support, do not implement CancelSupport ourselves
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 22 Apr 2013 19:17:29 +0200 |
| parents | 2f9ed6bcefa2 |
| children | 98ff1fb49abe |
comparison
equal
deleted
inserted
replaced
| 581:0890628ed51e | 582:90df078d6418 |
|---|---|
| 21 import static org.tmatesoft.hg.repo.HgRepository.*; | 21 import static org.tmatesoft.hg.repo.HgRepository.*; |
| 22 | 22 |
| 23 import java.io.IOException; | 23 import java.io.IOException; |
| 24 import java.util.ConcurrentModificationException; | 24 import java.util.ConcurrentModificationException; |
| 25 | 25 |
| 26 import org.tmatesoft.hg.internal.AdapterPlug; | |
| 26 import org.tmatesoft.hg.internal.ChangelogHelper; | 27 import org.tmatesoft.hg.internal.ChangelogHelper; |
| 27 import org.tmatesoft.hg.internal.Internals; | 28 import org.tmatesoft.hg.internal.Internals; |
| 28 import org.tmatesoft.hg.repo.HgRepository; | 29 import org.tmatesoft.hg.repo.HgRepository; |
| 29 import org.tmatesoft.hg.repo.HgRuntimeException; | 30 import org.tmatesoft.hg.repo.HgRuntimeException; |
| 30 import org.tmatesoft.hg.repo.HgStatusCollector; | 31 import org.tmatesoft.hg.repo.HgStatusCollector; |
| 31 import org.tmatesoft.hg.repo.HgStatusInspector; | 32 import org.tmatesoft.hg.repo.HgStatusInspector; |
| 32 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; | 33 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; |
| 34 import org.tmatesoft.hg.util.Adaptable; | |
| 33 import org.tmatesoft.hg.util.CancelSupport; | 35 import org.tmatesoft.hg.util.CancelSupport; |
| 34 import org.tmatesoft.hg.util.CancelledException; | 36 import org.tmatesoft.hg.util.CancelledException; |
| 35 import org.tmatesoft.hg.util.Path; | 37 import org.tmatesoft.hg.util.Path; |
| 36 import org.tmatesoft.hg.util.Outcome; | 38 import org.tmatesoft.hg.util.Outcome; |
| 37 | 39 |
| 194 sc.change(endRevision, mediator); | 196 sc.change(endRevision, mediator); |
| 195 } else { | 197 } else { |
| 196 sc.walk(startRevision, endRevision, mediator); | 198 sc.walk(startRevision, endRevision, mediator); |
| 197 } | 199 } |
| 198 } | 200 } |
| 199 } catch (CancelledException ex) { | |
| 200 // this is our exception, thrown from Mediator. | |
| 201 // next check shall throw original cause of the stop - either HgCallbackTargetException or original CancelledException | |
| 202 mediator.checkFailure(); | 201 mediator.checkFailure(); |
| 203 } catch (HgRuntimeException ex) { | 202 } catch (HgRuntimeException ex) { |
| 204 throw new HgLibraryFailureException(ex); | 203 throw new HgLibraryFailureException(ex); |
| 205 } finally { | 204 } finally { |
| 206 mediator.done(); | 205 mediator.done(); |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 private class Mediator implements HgStatusInspector, CancelSupport { | 209 private class Mediator extends AdapterPlug implements HgStatusInspector, Adaptable { |
| 211 boolean needModified; | 210 boolean needModified; |
| 212 boolean needAdded; | 211 boolean needAdded; |
| 213 boolean needRemoved; | 212 boolean needRemoved; |
| 214 boolean needUnknown; | 213 boolean needUnknown; |
| 215 boolean needMissing; | 214 boolean needMissing; |
| 216 boolean needClean; | 215 boolean needClean; |
| 217 boolean needIgnored; | 216 boolean needIgnored; |
| 218 boolean needCopies; | 217 boolean needCopies; |
| 219 HgStatusHandler handler; | 218 HgStatusHandler handler; |
| 220 private ChangelogHelper logHelper; | 219 private ChangelogHelper logHelper; |
| 221 private CancelSupport handlerCancelSupport; | |
| 222 private HgCallbackTargetException failure; | 220 private HgCallbackTargetException failure; |
| 223 private CancelledException cancellation; | |
| 224 | 221 |
| 225 Mediator() { | 222 Mediator() { |
| 226 } | 223 } |
| 227 | 224 |
| 228 public void start(HgStatusHandler h, CancelSupport hcs, ChangelogHelper changelogHelper) { | 225 public void start(HgStatusHandler h, CancelSupport hcs, ChangelogHelper changelogHelper) { |
| 229 handler = h; | 226 handler = h; |
| 230 handlerCancelSupport = hcs; | 227 super.attachAdapter(CancelSupport.class, hcs); |
| 231 logHelper = changelogHelper; | 228 logHelper = changelogHelper; |
| 232 } | 229 } |
| 233 | 230 |
| 234 public void done() { | 231 public void done() { |
| 235 handler = null; | 232 handler = null; |
| 236 handlerCancelSupport = null; | 233 super.detachAdapter(CancelSupport.class); |
| 237 logHelper = null; | 234 logHelper = null; |
| 238 failure = null; | 235 failure = null; |
| 239 cancellation = null; | |
| 240 } | 236 } |
| 241 | 237 |
| 242 public boolean busy() { | 238 public boolean busy() { |
| 243 return handler != null; | 239 return handler != null; |
| 244 } | 240 } |
| 245 | 241 |
| 246 // XXX copy from ChangesetTransformer. Perhaps, can share the code? | 242 // XXX similar code in ChangesetTransformer |
| 247 public void checkFailure() throws HgCallbackTargetException, CancelledException { | 243 public void checkFailure() throws HgCallbackTargetException { |
| 248 // do not forget to clear exceptions for reuse of this instance | 244 // do not forget to clear exceptions for reuse of this instance |
| 249 if (failure != null) { | 245 if (failure != null) { |
| 250 HgCallbackTargetException toThrow = failure; | 246 HgCallbackTargetException toThrow = failure; |
| 251 failure = null; | 247 failure = null; |
| 252 throw toThrow; | 248 throw toThrow; |
| 253 } | 249 } |
| 254 if (cancellation != null) { | |
| 255 CancelledException toThrow = cancellation; | |
| 256 cancellation = null; | |
| 257 throw toThrow; | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 // XXX copy from ChangesetTransformer. code sharing note above applies | |
| 262 public void checkCancelled() throws CancelledException { | |
| 263 if (failure != null || cancellation != null) { | |
| 264 // stop status iteration. Our exception is for the purposes of cancellation only, | |
| 265 // the one we have stored (this.cancellation) is for user | |
| 266 throw new CancelledException(); | |
| 267 } | |
| 268 } | 250 } |
| 269 | 251 |
| 270 private void dispatch(HgStatus s) { | 252 private void dispatch(HgStatus s) { |
| 271 try { | 253 try { |
| 272 handler.status(s); | 254 handler.status(s); |
| 273 handlerCancelSupport.checkCancelled(); | |
| 274 } catch (HgCallbackTargetException ex) { | 255 } catch (HgCallbackTargetException ex) { |
| 275 failure = ex; | 256 failure = ex; |
| 276 } catch (CancelledException ex) { | |
| 277 cancellation = ex; | |
| 278 } | 257 } |
| 279 } | 258 } |
| 280 | 259 |
| 281 public void modified(Path fname) { | 260 public void modified(Path fname) { |
| 282 if (needModified) { | 261 if (needModified) { |
| 321 } | 300 } |
| 322 | 301 |
| 323 public void invalid(Path fname, Exception err) { | 302 public void invalid(Path fname, Exception err) { |
| 324 try { | 303 try { |
| 325 handler.error(fname, new Outcome(Outcome.Kind.Failure, "Failed to get file status", err)); | 304 handler.error(fname, new Outcome(Outcome.Kind.Failure, "Failed to get file status", err)); |
| 326 handlerCancelSupport.checkCancelled(); | |
| 327 } catch (HgCallbackTargetException ex) { | 305 } catch (HgCallbackTargetException ex) { |
| 328 failure = ex; | 306 failure = ex; |
| 329 } catch (CancelledException ex) { | |
| 330 cancellation = ex; | |
| 331 } | 307 } |
| 332 } | 308 } |
| 333 } | 309 } |
| 334 } | 310 } |
