Patchwork [3,of,3,V2] shelve: do not update when keeping changes, just move the dirstate

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date March 22, 2019, 5:18 p.m.
Message ID <370831f0c08f4f635874.1553275111@chloe>
Download mbox | patch
Permalink /patch/39363/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - March 22, 2019, 5:18 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1553268407 14400
#      Fri Mar 22 11:26:47 2019 -0400
# Node ID 370831f0c08f4f635874d6abb0505825024f6b36
# Parent  e61152452e42c8bd357618f389afca8492e05651
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.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -499,14 +499,19 @@  def _docreatecmd(ui, repo, pats, opts):
             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)
 
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -928,6 +928,20 @@  with general delta
   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