shelve: do not update when keeping changes, just move the dirstate
authorJordi Gutiérrez Hermoso <jordigh@octave.org>
Fri, 22 Mar 2019 11:26:47 -0400
changeset 42013 50d5e64ec561
parent 42012 9b78bbb76111
child 42014 d93436e2ca6b
shelve: do not update when keeping changes, just move the dirstate This is to leave the working directory unchanged. We reuse the match object as an optimisation.
hgext/shelve.py
tests/test-shelve.t
--- a/hgext/shelve.py	Fri Mar 22 13:03:26 2019 -0400
+++ b/hgext/shelve.py	Fri Mar 22 11:26:47 2019 -0400
@@ -499,14 +499,19 @@
             return 1
 
         # Create a matcher so that prefetch doesn't attempt to fetch
-        # the entire repository pointlessly
+        # the entire repository pointlessly, and as an optimisation
+        # for movedirstate, if needed.
         match = scmutil.matchfiles(repo, repo[node].files())
         _shelvecreatedcommit(repo, node, name, match)
 
         if ui.formatted():
             desc = stringutil.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
-        hg.update(repo, parent.node())
+        if opts['keep']:
+            with repo.dirstate.parentchange():
+                scmutil.movedirstate(repo, parent, match)
+        else:
+            hg.update(repo, parent.node())
         if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
             repo.dirstate.setbranch(origbranch)
 
--- a/tests/test-shelve.t	Fri Mar 22 13:03:26 2019 -0400
+++ b/tests/test-shelve.t	Fri Mar 22 11:26:47 2019 -0400
@@ -928,6 +928,20 @@
   Stream params: {Compression: BZ}
   changegroup -- {nbchanges: 1, version: 02} (mandatory: True)
       330882a04d2ce8487636b1fb292e5beea77fa1e3
+
+Test shelve --keep
+
+  $ hg unshelve
+  unshelving change 'default'
+  $ hg shelve --keep
+  shelved as default
+  $ hg diff
+  diff --git a/jungle b/jungle
+  new file mode 100644
+  --- /dev/null
+  +++ b/jungle
+  @@ -0,0 +1,1 @@
+  +babar
   $ cd ..
 
 Test visibility of in-memory changes inside transaction to external hook