diff src/org/tmatesoft/hg/core/HgAddRemoveCommand.java @ 581:0890628ed51e

Progress/cancel support in new commands
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 22 Apr 2013 16:02:17 +0200
parents 95bdcf75e71e
children f41dd9a3b8af
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgAddRemoveCommand.java	Fri Apr 19 20:30:34 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgAddRemoveCommand.java	Mon Apr 22 16:02:17 2013 +0200
@@ -25,7 +25,10 @@
 import org.tmatesoft.hg.repo.HgManifest.Flags;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgRuntimeException;
+import org.tmatesoft.hg.util.CancelSupport;
+import org.tmatesoft.hg.util.CancelledException;
 import org.tmatesoft.hg.util.Path;
+import org.tmatesoft.hg.util.ProgressSupport;
 
 /**
  * WORK IN PROGRESS
@@ -94,20 +97,33 @@
 	/**
 	 * Perform scheduled addition/removal
 	 * 
-	 * @throws HgException
+	 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
+	 * @throws CancelledException if execution of the command was cancelled
 	 */
-	public void execute() throws HgException {
+	public void execute() throws HgException, CancelledException {
 		try {
+			final ProgressSupport progress = getProgressSupport(null);
+			final CancelSupport cancellation = getCancelSupport(null, true);
+			cancellation.checkCancelled();
+			progress.start(2 + toAdd.size() + toRemove.size());
 			Internals implRepo = Internals.getInstance(repo);
 			final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
 			dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
+			progress.worked(1);
+			cancellation.checkCancelled();
 			for (Path p : toAdd) {
 				dirstateBuilder.recordAdded(p, Flags.RegularFile, -1);
+				progress.worked(1);
+				cancellation.checkCancelled();
 			}
 			for (Path p : toRemove) {
 				dirstateBuilder.recordRemoved(p);
+				progress.worked(1);
+				cancellation.checkCancelled();
 			}
 			dirstateBuilder.serialize();
+			progress.worked(1);
+			progress.done();
 		} catch (HgRuntimeException ex) {
 			throw new HgLibraryFailureException(ex);
 		}