transplant: wrap a transaction around the whole command
authorGreg Ward <greg@gerg.ca>
Tue, 04 Oct 2011 19:43:45 -0400
changeset 15204 3ce9b1a7538b
parent 15203 c7ce651a6bc9
child 15205 4e5b7d130e76
transplant: wrap a transaction around the whole command
hgext/transplant.py
tests/test-transplant.t
--- a/hgext/transplant.py	Fri Oct 07 17:08:24 2011 -0500
+++ b/hgext/transplant.py	Tue Oct 04 19:43:45 2011 -0400
@@ -105,10 +105,11 @@
         diffopts = patch.diffopts(self.ui, opts)
         diffopts.git = True
 
-        lock = wlock = None
+        lock = wlock = tr = None
         try:
             wlock = repo.wlock()
             lock = repo.lock()
+            tr = repo.transaction('transplant')
             for rev in revs:
                 node = revmap[rev]
                 revstr = '%s:%s' % (rev, short(node))
@@ -172,12 +173,15 @@
                     finally:
                         if patchfile:
                             os.unlink(patchfile)
+            tr.close()
             if pulls:
                 repo.pull(source, heads=pulls)
                 merge.update(repo, pulls[-1], False, False, None)
         finally:
             self.saveseries(revmap, merges)
             self.transplants.write()
+            if tr:
+                tr.release()
             lock.release()
             wlock.release()
 
--- a/tests/test-transplant.t	Fri Oct 07 17:08:24 2011 -0500
+++ b/tests/test-transplant.t	Tue Oct 04 19:43:45 2011 -0400
@@ -81,6 +81,19 @@
   1 
   0 
 
+rollback the transplant
+  $ hg rollback
+  repository tip rolled back to revision 4 (undo transplant)
+  working directory now based on revision 1
+  $ hg tip -q
+  4:a53251cdf717
+  $ hg parents -q
+  1:d11e3596cc1a
+  $ hg status
+  ? b1
+  ? b2
+  ? b3
+
   $ hg clone ../t ../prune
   updating to branch default
   4 files updated, 0 files merged, 0 files removed, 0 files unresolved