comparison src/org/tmatesoft/hg/core/HgRevertCommand.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 78a9e26e670d
children f41dd9a3b8af
comparison
equal deleted inserted replaced
580:bd5926e24aa3 581:0890628ed51e
28 import org.tmatesoft.hg.internal.Internals; 28 import org.tmatesoft.hg.internal.Internals;
29 import org.tmatesoft.hg.repo.HgManifest; 29 import org.tmatesoft.hg.repo.HgManifest;
30 import org.tmatesoft.hg.repo.HgManifest.Flags; 30 import org.tmatesoft.hg.repo.HgManifest.Flags;
31 import org.tmatesoft.hg.repo.HgRepository; 31 import org.tmatesoft.hg.repo.HgRepository;
32 import org.tmatesoft.hg.repo.HgRuntimeException; 32 import org.tmatesoft.hg.repo.HgRuntimeException;
33 import org.tmatesoft.hg.util.CancelSupport;
33 import org.tmatesoft.hg.util.CancelledException; 34 import org.tmatesoft.hg.util.CancelledException;
34 import org.tmatesoft.hg.util.Path; 35 import org.tmatesoft.hg.util.Path;
36 import org.tmatesoft.hg.util.ProgressSupport;
35 37
36 /** 38 /**
37 * WORK IN PROGRESS. 39 * WORK IN PROGRESS.
38 * 40 *
39 * Restore files to their checkout state, 'hg revert' counterpart. 41 * Restore files to their checkout state, 'hg revert' counterpart.
93 // TODO keepOriginal() to save .orig (with tests!) 95 // TODO keepOriginal() to save .orig (with tests!)
94 96
95 /** 97 /**
96 * Perform the back out for the given files 98 * Perform the back out for the given files
97 * 99 *
98 * @throws HgIOException 100 * @throws HgIOException to indicate troubles updating files in working copy
99 * @throws HgException 101 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
100 * @throws CancelledException 102 * @throws CancelledException if execution of the command was cancelled
101 */ 103 */
102 public void execute() throws HgException, CancelledException { 104 public void execute() throws HgException, CancelledException {
103 try { 105 try {
106 final ProgressSupport progress = getProgressSupport(null);
107 final CancelSupport cancellation = getCancelSupport(null, true);
108 cancellation.checkCancelled();
109 progress.start(files.size() + 2);
104 final int csetRevision; 110 final int csetRevision;
105 if (changesetToCheckout.get() == HgRepository.WORKING_COPY) { 111 if (changesetToCheckout.get() == HgRepository.WORKING_COPY) {
106 csetRevision = repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first()); 112 csetRevision = repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first());
107 } else { 113 } else {
108 csetRevision = changesetToCheckout.get(); 114 csetRevision = changesetToCheckout.get();
109 } 115 }
110 Internals implRepo = Internals.getInstance(repo); 116 Internals implRepo = Internals.getInstance(repo);
111 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo); 117 final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
112 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource())); 118 dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
119 progress.worked(1);
120 cancellation.checkCancelled();
121
113 final HgCheckoutCommand.CheckoutWorker worker = new HgCheckoutCommand.CheckoutWorker(implRepo); 122 final HgCheckoutCommand.CheckoutWorker worker = new HgCheckoutCommand.CheckoutWorker(implRepo);
114 123
115 HgManifest.Inspector insp = new HgManifest.Inspector() { 124 HgManifest.Inspector insp = new HgManifest.Inspector() {
116 125
117 public boolean next(Nodeid nid, Path fname, Flags flags) { 126 public boolean next(Nodeid nid, Path fname, Flags flags) {
144 f.delete(); 153 f.delete();
145 } 154 }
146 } 155 }
147 repo.getManifest().walkFileRevisions(file, insp, csetRevision); 156 repo.getManifest().walkFileRevisions(file, insp, csetRevision);
148 worker.checkFailed(); 157 worker.checkFailed();
158 progress.worked(1);
159 cancellation.checkCancelled();
149 } 160 }
150 dirstateBuilder.serialize(); 161 dirstateBuilder.serialize();
162 progress.worked(1);
163 progress.done();
151 } catch (HgRuntimeException ex) { 164 } catch (HgRuntimeException ex) {
152 throw new HgLibraryFailureException(ex); 165 throw new HgLibraryFailureException(ex);
153 } 166 }
154 } 167 }
155 } 168 }