Patchwork [2,of,2] shelve: add dirstateguard to unshelve

login
register
mail settings
Submitter Durham Goode
Date Sept. 29, 2015, 2:07 a.m.
Message ID <50ce9941d7c0ce0abf4b.1443492423@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10677/
State Accepted
Headers show

Comments

Durham Goode - Sept. 29, 2015, 2:07 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1443492037 25200
#      Mon Sep 28 19:00:37 2015 -0700
# Node ID 50ce9941d7c0ce0abf4b3c9e616057a82e6c9021
# Parent  ff1ab706e6d662d1971c1a6127e60b7063abfe74
shelve: add dirstateguard to unshelve

If unshelve threw an exception at an inopportune moment, it would cause an
unknown working copy parent. Adding the dirstateguard prevents this.

I tested it by manually introducing exceptions in various locations within
unshelve.
Augie Fackler - Sept. 29, 2015, 1:38 p.m.
On Mon, Sep 28, 2015 at 07:07:03PM -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1443492037 25200
> #      Mon Sep 28 19:00:37 2015 -0700
> # Node ID 50ce9941d7c0ce0abf4b3c9e616057a82e6c9021
> # Parent  ff1ab706e6d662d1971c1a6127e60b7063abfe74
> shelve: add dirstateguard to unshelve

very nice, queued these

>
> If unshelve threw an exception at an inopportune moment, it would cause an
> unknown working copy parent. Adding the dirstateguard prevents this.
>
> I tested it by manually introducing exceptions in various locations within
> unshelve.
>
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -619,6 +619,8 @@ def unshelve(ui, repo, *shelved, **opts)
>          wlock = repo.wlock()
>          lock = repo.lock()
>
> +        dsguard = cmdutil.dirstateguard(repo, 'unshelve')
> +
>          tr = repo.transaction('unshelve', report=lambda x: None)
>          oldtiprev = len(repo)
>
> @@ -676,6 +678,7 @@ def unshelve(ui, repo, *shelved, **opts)
>                  })
>              except error.InterventionRequired:
>                  tr.close()
> +                dsguard.close()
>
>                  stripnodes = [repo.changelog.node(rev)
>                                for rev in xrange(oldtiprev, len(repo))]
> @@ -695,6 +698,7 @@ def unshelve(ui, repo, *shelved, **opts)
>                  shelvectx = tmpwctx
>
>          mergefiles(ui, repo, pctx, shelvectx)
> +        dsguard.close()
>          shelvedstate.clear(repo)
>
>          # The transaction aborting will strip all the commits for us,
> @@ -708,6 +712,8 @@ def unshelve(ui, repo, *shelved, **opts)
>          ui.quiet = oldquiet
>          if tr:
>              tr.release()
> +        if dsguard:
> +            dsguard.release()
>          lockmod.release(lock, wlock)
>
>  @command('shelve',
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -619,6 +619,8 @@  def unshelve(ui, repo, *shelved, **opts)
         wlock = repo.wlock()
         lock = repo.lock()
 
+        dsguard = cmdutil.dirstateguard(repo, 'unshelve')
+
         tr = repo.transaction('unshelve', report=lambda x: None)
         oldtiprev = len(repo)
 
@@ -676,6 +678,7 @@  def unshelve(ui, repo, *shelved, **opts)
                 })
             except error.InterventionRequired:
                 tr.close()
+                dsguard.close()
 
                 stripnodes = [repo.changelog.node(rev)
                               for rev in xrange(oldtiprev, len(repo))]
@@ -695,6 +698,7 @@  def unshelve(ui, repo, *shelved, **opts)
                 shelvectx = tmpwctx
 
         mergefiles(ui, repo, pctx, shelvectx)
+        dsguard.close()
         shelvedstate.clear(repo)
 
         # The transaction aborting will strip all the commits for us,
@@ -708,6 +712,8 @@  def unshelve(ui, repo, *shelved, **opts)
         ui.quiet = oldquiet
         if tr:
             tr.release()
+        if dsguard:
+            dsguard.release()
         lockmod.release(lock, wlock)
 
 @command('shelve',