comparison 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
comparison
equal deleted inserted replaced
580:bd5926e24aa3 581:0890628ed51e
23 import org.tmatesoft.hg.internal.Experimental; 23 import org.tmatesoft.hg.internal.Experimental;
24 import org.tmatesoft.hg.internal.Internals; 24 import org.tmatesoft.hg.internal.Internals;
25 import org.tmatesoft.hg.repo.HgManifest.Flags; 25 import org.tmatesoft.hg.repo.HgManifest.Flags;
26 import org.tmatesoft.hg.repo.HgRepository; 26 import org.tmatesoft.hg.repo.HgRepository;
27 import org.tmatesoft.hg.repo.HgRuntimeException; 27 import org.tmatesoft.hg.repo.HgRuntimeException;
28 import org.tmatesoft.hg.util.CancelSupport;
29 import org.tmatesoft.hg.util.CancelledException;
28 import org.tmatesoft.hg.util.Path; 30 import org.tmatesoft.hg.util.Path;
31 import org.tmatesoft.hg.util.ProgressSupport;
29 32
30 /** 33 /**
31 * WORK IN PROGRESS 34 * WORK IN PROGRESS
32 * 35 *
33 * Schedule files for addition and removal 36 * Schedule files for addition and removal
92 } 95 }
93 96
94 /** 97 /**
95 * Perform scheduled addition/removal 98 * Perform scheduled addition/removal
96 * 99 *
97 * @throws HgException 100 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
101 * @throws CancelledException if execution of the command was cancelled
98 */ 102 */
99 public void execute() throws HgException { 103 public void execute() throws HgException, CancelledException {
100 try { 104 try {
105 final ProgressSupport progress = getProgressSupport(null);
106 final CancelSupport cancellation = getCancelSupport(null, true);
107 cancellation.checkCancelled();
108 progress.start(2 + toAdd.size() + toRemove.size());
101 Internals implRepo = Internals.getInstance(repo); 109 Internals implRepo = Internals.getInstance(repo);
102 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo); 110 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
103 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource())); 111 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
112 progress.worked(1);
113 cancellation.checkCancelled();
104 for (Path p : toAdd) { 114 for (Path p : toAdd) {
105 dirstateBuilder.recordAdded(p, Flags.RegularFile, -1); 115 dirstateBuilder.recordAdded(p, Flags.RegularFile, -1);
116 progress.worked(1);
117 cancellation.checkCancelled();
106 } 118 }
107 for (Path p : toRemove) { 119 for (Path p : toRemove) {
108 dirstateBuilder.recordRemoved(p); 120 dirstateBuilder.recordRemoved(p);
121 progress.worked(1);
122 cancellation.checkCancelled();
109 } 123 }
110 dirstateBuilder.serialize(); 124 dirstateBuilder.serialize();
125 progress.worked(1);
126 progress.done();
111 } catch (HgRuntimeException ex) { 127 } catch (HgRuntimeException ex) {
112 throw new HgLibraryFailureException(ex); 128 throw new HgLibraryFailureException(ex);
113 } 129 }
114 } 130 }
115 } 131 }