Mercurial > jhg
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgRevertCommand.java Tue May 14 17:31:35 2013 +0200 +++ b/src/org/tmatesoft/hg/core/HgRevertCommand.java Wed May 15 20:10:09 2013 +0200 @@ -21,13 +21,16 @@ import java.util.LinkedHashSet; import java.util.Set; +import org.tmatesoft.hg.internal.COWTransaction; import org.tmatesoft.hg.internal.CsetParamKeeper; import org.tmatesoft.hg.internal.DirstateBuilder; import org.tmatesoft.hg.internal.DirstateReader; import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.Transaction; import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.repo.HgRepositoryLock; import org.tmatesoft.hg.repo.HgRuntimeException; import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; @@ -99,6 +102,8 @@ * @throws CancelledException if execution of the command was cancelled */ public void execute() throws HgException, CancelledException { + final HgRepositoryLock wdLock = repo.getWorkingDirLock(); + wdLock.acquire(); try { final ProgressSupport progress = getProgressSupport(null); final CancelSupport cancellation = getCancelSupport(null, true); @@ -155,11 +160,25 @@ progress.worked(1); cancellation.checkCancelled(); } - dirstateBuilder.serialize(); + Transaction.Factory trFactory = new COWTransaction.Factory(); + Transaction tr = trFactory.create(repo); + try { + // TODO same code in HgAddRemoveCommand and similar in HgCommitCommand + dirstateBuilder.serialize(tr); + tr.commit(); + } catch (RuntimeException ex) { + tr.rollback(); + throw ex; + } catch (HgException ex) { + tr.rollback(); + throw ex; + } progress.worked(1); progress.done(); } catch (HgRuntimeException ex) { throw new HgLibraryFailureException(ex); + } finally { + wdLock.release(); } } }