diff hgext/shelve.py @ 42013:50d5e64ec561

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.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Fri, 22 Mar 2019 11:26:47 -0400
parents 9b78bbb76111
children 00c1ee0f746a
line wrap: on
line diff
--- 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)