comparison src/org/tmatesoft/hg/core/HgRevertCommand.java @ 617:65c01508f002

Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 15 May 2013 20:10:09 +0200
parents f41dd9a3b8af
children b4242b7e7dfe
comparison
equal deleted inserted replaced
616:5e0313485eef 617:65c01508f002
19 import java.io.File; 19 import java.io.File;
20 import java.util.Arrays; 20 import java.util.Arrays;
21 import java.util.LinkedHashSet; 21 import java.util.LinkedHashSet;
22 import java.util.Set; 22 import java.util.Set;
23 23
24 import org.tmatesoft.hg.internal.COWTransaction;
24 import org.tmatesoft.hg.internal.CsetParamKeeper; 25 import org.tmatesoft.hg.internal.CsetParamKeeper;
25 import org.tmatesoft.hg.internal.DirstateBuilder; 26 import org.tmatesoft.hg.internal.DirstateBuilder;
26 import org.tmatesoft.hg.internal.DirstateReader; 27 import org.tmatesoft.hg.internal.DirstateReader;
27 import org.tmatesoft.hg.internal.Internals; 28 import org.tmatesoft.hg.internal.Internals;
29 import org.tmatesoft.hg.internal.Transaction;
28 import org.tmatesoft.hg.repo.HgManifest; 30 import org.tmatesoft.hg.repo.HgManifest;
29 import org.tmatesoft.hg.repo.HgManifest.Flags; 31 import org.tmatesoft.hg.repo.HgManifest.Flags;
30 import org.tmatesoft.hg.repo.HgRepository; 32 import org.tmatesoft.hg.repo.HgRepository;
33 import org.tmatesoft.hg.repo.HgRepositoryLock;
31 import org.tmatesoft.hg.repo.HgRuntimeException; 34 import org.tmatesoft.hg.repo.HgRuntimeException;
32 import org.tmatesoft.hg.util.CancelSupport; 35 import org.tmatesoft.hg.util.CancelSupport;
33 import org.tmatesoft.hg.util.CancelledException; 36 import org.tmatesoft.hg.util.CancelledException;
34 import org.tmatesoft.hg.util.Path; 37 import org.tmatesoft.hg.util.Path;
35 import org.tmatesoft.hg.util.ProgressSupport; 38 import org.tmatesoft.hg.util.ProgressSupport;
97 * @throws HgIOException to indicate troubles updating files in working copy 100 * @throws HgIOException to indicate troubles updating files in working copy
98 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state 101 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
99 * @throws CancelledException if execution of the command was cancelled 102 * @throws CancelledException if execution of the command was cancelled
100 */ 103 */
101 public void execute() throws HgException, CancelledException { 104 public void execute() throws HgException, CancelledException {
105 final HgRepositoryLock wdLock = repo.getWorkingDirLock();
106 wdLock.acquire();
102 try { 107 try {
103 final ProgressSupport progress = getProgressSupport(null); 108 final ProgressSupport progress = getProgressSupport(null);
104 final CancelSupport cancellation = getCancelSupport(null, true); 109 final CancelSupport cancellation = getCancelSupport(null, true);
105 cancellation.checkCancelled(); 110 cancellation.checkCancelled();
106 progress.start(files.size() + 2); 111 progress.start(files.size() + 2);
153 repo.getManifest().walkFileRevisions(file, insp, csetRevision); 158 repo.getManifest().walkFileRevisions(file, insp, csetRevision);
154 worker.checkFailed(); 159 worker.checkFailed();
155 progress.worked(1); 160 progress.worked(1);
156 cancellation.checkCancelled(); 161 cancellation.checkCancelled();
157 } 162 }
158 dirstateBuilder.serialize(); 163 Transaction.Factory trFactory = new COWTransaction.Factory();
164 Transaction tr = trFactory.create(repo);
165 try {
166 // TODO same code in HgAddRemoveCommand and similar in HgCommitCommand
167 dirstateBuilder.serialize(tr);
168 tr.commit();
169 } catch (RuntimeException ex) {
170 tr.rollback();
171 throw ex;
172 } catch (HgException ex) {
173 tr.rollback();
174 throw ex;
175 }
159 progress.worked(1); 176 progress.worked(1);
160 progress.done(); 177 progress.done();
161 } catch (HgRuntimeException ex) { 178 } catch (HgRuntimeException ex) {
162 throw new HgLibraryFailureException(ex); 179 throw new HgLibraryFailureException(ex);
180 } finally {
181 wdLock.release();
163 } 182 }
164 } 183 }
165 } 184 }