[PATCH 3 of 4] shelve: use rollback instead of aborting a current transaction for shelve

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Oct 4 07:44:19 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1443962009 -32400
#      Sun Oct 04 21:33:29 2015 +0900
# Node ID e265a8c85c3873815730921ae2d8ca3c6df3b48a
# Parent  ce4ea67c82972f2988e42372cd6443b6c288e1c8
shelve: use rollback instead of aborting a current transaction for shelve

Before this patch, "hg shelve" uses aborting a current transaction to
discard temporary changes while shelving.

This assumes that dirstate changes in a transaction scope are kept
even after aborting it. But this assumption will be broken by
"transactional dirstate". See the wiki page below for detail about it.

    https://mercurial.selenic.com/wiki/DirstateTransactionPlan

This patch uses 'repo.rollback()' instead of aborting current
transaction to remove the temporary revision for "hg shelve"

'dirstate.write()' just before closing a transaction will be removed
soon by subsequent patch, which writes or discards in-memory dirstate
changes at releasing transaction according to the result of it.

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -301,6 +301,19 @@
             desc = util.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
         hg.update(repo, parent.node())
+
+        repo.dirstate.write() # certainly writes all changes while shelving
+        tr.close()
+        tr.release() # is ensured to run successfully by previous 'close()'
+        tr = None
+
+        # this rollbacking discards changes while shelving by
+        # restoring from undo files, but keeps dirstate as it is,
+        # because 'hg.update()' already updates the working directory
+        # to original parent (= not "parent gone")
+        repo.ui.pushbuffer()
+        repo.rollback(force=True)
+        repo.ui.popbuffer()
     finally:
         if tr:
             tr.abort()


More information about the Mercurial-devel mailing list