[PATCH 1 of 2] shelve: add dirstateguard to prevent unknown working copy parent

Durham Goode durham at fb.com
Tue Sep 29 02:07:02 UTC 2015


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1443491489 25200
#      Mon Sep 28 18:51:29 2015 -0700
# Node ID ff1ab706e6d662d1971c1a6127e60b7063abfe74
# Parent  0224d22ef5d815c86d7ebce6644f056c406acbfd
shelve: add dirstateguard to prevent unknown working copy parent

Previously, ctrl+c during a shelve was extremely likely to cause you to lose
your working copy parent. The dirstateguard should prevent this.

I tested this by adding a hardcoded exception in the middle of the shelve (after
the initial commit) and verified hg status was correct afterwards.

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -246,6 +246,7 @@ def createcmd(ui, repo, pats, opts):
     try:
         wlock = repo.wlock()
         lock = repo.lock()
+        dsguard = cmdutil.dirstateguard(repo, 'shelve')
 
         bms = repo._bookmarks.copy()
         # use an uncommitted transaction to generate the bundle to avoid
@@ -302,6 +303,7 @@ def createcmd(ui, repo, pats, opts):
             desc = util.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
         hg.update(repo, parent.node())
+        dsguard.close()
     finally:
         if bms:
             # restore old bookmarks
@@ -309,6 +311,8 @@ def createcmd(ui, repo, pats, opts):
             repo._bookmarks.write()
         if tr:
             tr.abort()
+        if dsguard:
+            dsguard.release()
         lockmod.release(lock, wlock)
 
 def cleanupcmd(ui, repo):


More information about the Mercurial-devel mailing list