Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/HgAddRemoveCommand.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 |
|---|---|
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.core; | 17 package org.tmatesoft.hg.core; |
| 18 | 18 |
| 19 import java.util.LinkedHashSet; | 19 import java.util.LinkedHashSet; |
| 20 | 20 |
| 21 import org.tmatesoft.hg.internal.COWTransaction; | |
| 21 import org.tmatesoft.hg.internal.DirstateBuilder; | 22 import org.tmatesoft.hg.internal.DirstateBuilder; |
| 22 import org.tmatesoft.hg.internal.DirstateReader; | 23 import org.tmatesoft.hg.internal.DirstateReader; |
| 23 import org.tmatesoft.hg.internal.Internals; | 24 import org.tmatesoft.hg.internal.Internals; |
| 25 import org.tmatesoft.hg.internal.Transaction; | |
| 24 import org.tmatesoft.hg.repo.HgManifest.Flags; | 26 import org.tmatesoft.hg.repo.HgManifest.Flags; |
| 25 import org.tmatesoft.hg.repo.HgRepository; | 27 import org.tmatesoft.hg.repo.HgRepository; |
| 28 import org.tmatesoft.hg.repo.HgRepositoryLock; | |
| 26 import org.tmatesoft.hg.repo.HgRuntimeException; | 29 import org.tmatesoft.hg.repo.HgRuntimeException; |
| 27 import org.tmatesoft.hg.util.CancelSupport; | 30 import org.tmatesoft.hg.util.CancelSupport; |
| 28 import org.tmatesoft.hg.util.CancelledException; | 31 import org.tmatesoft.hg.util.CancelledException; |
| 29 import org.tmatesoft.hg.util.Path; | 32 import org.tmatesoft.hg.util.Path; |
| 30 import org.tmatesoft.hg.util.ProgressSupport; | 33 import org.tmatesoft.hg.util.ProgressSupport; |
| 92 | 95 |
| 93 /** | 96 /** |
| 94 * Perform scheduled addition/removal | 97 * Perform scheduled addition/removal |
| 95 * | 98 * |
| 96 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state | 99 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state |
| 100 * @throws HgRepositoryLockException if failed to lock the repo for modifications | |
| 97 * @throws CancelledException if execution of the command was cancelled | 101 * @throws CancelledException if execution of the command was cancelled |
| 98 */ | 102 */ |
| 99 public void execute() throws HgException, CancelledException { | 103 public void execute() throws HgException, HgRepositoryLockException, CancelledException { |
| 104 final HgRepositoryLock wdLock = repo.getWorkingDirLock(); | |
| 105 wdLock.acquire(); | |
| 100 try { | 106 try { |
| 101 final ProgressSupport progress = getProgressSupport(null); | 107 final ProgressSupport progress = getProgressSupport(null); |
| 102 final CancelSupport cancellation = getCancelSupport(null, true); | 108 final CancelSupport cancellation = getCancelSupport(null, true); |
| 103 cancellation.checkCancelled(); | 109 cancellation.checkCancelled(); |
| 104 progress.start(2 + toAdd.size() + toRemove.size()); | 110 progress.start(2 + toAdd.size() + toRemove.size()); |
| 115 for (Path p : toRemove) { | 121 for (Path p : toRemove) { |
| 116 dirstateBuilder.recordRemoved(p); | 122 dirstateBuilder.recordRemoved(p); |
| 117 progress.worked(1); | 123 progress.worked(1); |
| 118 cancellation.checkCancelled(); | 124 cancellation.checkCancelled(); |
| 119 } | 125 } |
| 120 dirstateBuilder.serialize(); | 126 Transaction.Factory trFactory = new COWTransaction.Factory(); |
| 127 Transaction tr = trFactory.create(repo); | |
| 128 try { | |
| 129 dirstateBuilder.serialize(tr); | |
| 130 tr.commit(); | |
| 131 } catch (RuntimeException ex) { | |
| 132 tr.rollback(); | |
| 133 throw ex; | |
| 134 } catch (HgException ex) { | |
| 135 tr.rollback(); | |
| 136 throw ex; | |
| 137 } | |
| 121 progress.worked(1); | 138 progress.worked(1); |
| 122 progress.done(); | 139 progress.done(); |
| 123 } catch (HgRuntimeException ex) { | 140 } catch (HgRuntimeException ex) { |
| 124 throw new HgLibraryFailureException(ex); | 141 throw new HgLibraryFailureException(ex); |
| 142 } finally { | |
| 143 wdLock.release(); | |
| 125 } | 144 } |
| 126 } | 145 } |
| 127 } | 146 } |
