From patchwork Sun Oct 4 12:44:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3, of, 4] shelve: use rollback instead of aborting a current transaction for shelve From: Katsunori FUJIWARA X-Patchwork-Id: 10772 Message-Id: To: mercurial-devel@selenic.com Date: Sun, 04 Oct 2015 21:44:19 +0900 # HG changeset patch # User FUJIWARA Katsunori # 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()