Patchwork [05,of,25,RFC] shelve: directly handle `--continue`

login
register
mail settings
Submitter Boris Feld
Date June 7, 2018, 2:11 p.m.
Message ID <e58a468f9cc8f9286343.1528380664@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/31999/
State New
Headers show

Comments

Boris Feld - June 7, 2018, 2:11 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1527545628 -7200
#      Tue May 29 00:13:48 2018 +0200
# Node ID e58a468f9cc8f92863439bfe74c8414c22c25ce0
# Parent  d71e05a796d4a445136a9f62b6a57ab359fd1dee
# EXP-Topic graftshelve
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e58a468f9cc8
shelve: directly handle `--continue`

Shelve is currently sub-contracting some of its work to the rebase extension.
In order to make shelve more independent and flexible we would like shelve to
handle the parent alignment directly.

This changeset takes on the next step, handling the abort process. Same as for
--abort. It turns out we have all the necessary bits in the `shelvestate`
file. So we do not need anything from the interrupted rebase.

Differential Revision: https://phab.mercurial-scm.org/D3689

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -683,22 +683,37 @@  def unshelvecontinue(ui, repo, state, op
                 _("unresolved conflicts, can't continue"),
                 hint=_("see 'hg resolve', then 'hg unshelve --continue'"))
 
-        repo.vfs.rename('unshelverebasestate', 'rebasestate')
-        try:
-            rebase.rebase(ui, repo, **{
-                r'continue' : True
-            })
-        except Exception:
-            repo.vfs.rename('rebasestate', 'unshelverebasestate')
-            raise
+        shelvectx = repo[state.parents[1]]
+        pendingctx = state.pendingctx
+
+        overrides = {('phases', 'new-commit'): phases.secret}
+        with repo.ui.configoverride(overrides, 'unshelve'):
+            with repo.dirstate.parentchange():
+                repo.setparents(state.parents[0], nodemod.nullid)
+                newnode = repo.commit(text=shelvectx.description(),
+                                      extra=shelvectx.extra(),
+                                      user=shelvectx.user(),
+                                      date=shelvectx.date())
 
-        shelvectx = repo['tip']
-        if state.pendingctx not in shelvectx.parents():
-            # rebase was a no-op, so it produced no child commit
+        if newnode is None:
+            # If it ended up being a no-op commit, then the normal
+            # merge state clean-up path doesn't happen, so do it
+            # here. Fix issue5494
+            merge.mergestate.clean(repo)
             shelvectx = state.pendingctx
+            msg = _('note: unshelved changes already existed '
+                    'in the working copy\n')
+            ui.status(msg)
         else:
-            # only strip the shelvectx if the rebase produced it
-            state.nodestoremove.append(shelvectx.node())
+            # only strip the shelvectx if we produced one
+            state.nodestoremove.append(newnode)
+            shelvectx = repo[newnode]
+
+        hg.updaterepo(repo, pendingctx.node(), False)
+
+        if repo.vfs.exists('unshelverebasestate'):
+            repo.vfs.rename('unshelverebasestate', 'rebasestate')
+            rebase.clearstatus(repo)
 
         mergefiles(ui, repo, state.wctx, shelvectx)
         restorebranch(ui, repo, state.branchtorestore)
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -459,7 +459,6 @@  attempt to continue
   (continue: hg unshelve --continue)
   [255]
   $ hg unshelve -c
-  rebasing 5:32c69314e062 "changes to: [mq]: second.patch" (tip)
   unshelve of 'default' complete
 
 ensure the repo is as we hope
@@ -901,8 +900,7 @@  is a no-op), works (issue4398)
   (no more unresolved files)
   continue: hg unshelve --continue
   $ hg unshelve -c
-  rebasing 5:e42a7da90865 "changes to: second" (tip)
-  note: rebase of 5:e42a7da90865 created no changes to commit
+  note: unshelved changes already existed in the working copy
   unshelve of 'default' complete
   $ hg bookmark
    * test                      4:33f7f61e6c5e
@@ -1534,7 +1532,6 @@  will be preserved.
   (no more unresolved files)
   continue: hg unshelve --continue
   $ hg unshelve --continue
-  rebasing 2:425c97ef07f3 "changes to: a" (tip)
   marked working directory as branch test
   unshelve of 'default' complete
   $ cat a
@@ -1618,7 +1615,6 @@  in previous versions) and running unshel
   (no more unresolved files)
   continue: hg unshelve --continue
   $ hg unshelve --continue
-  rebasing 2:425c97ef07f3 "changes to: a" (tip)
   unshelve of 'default' complete
   $ cat a
   aaabbbccc
@@ -1722,7 +1718,6 @@  Unshelve respects --keep even if user in
   (no more unresolved files)
   continue: hg unshelve --continue
   $ hg unshelve --continue
-  rebasing 2:3fbe6fbb0bef "changes to: 1" (tip)
   unshelve of 'default' complete
   $ hg shelve --list
   default         (*s ago) * changes to: 1 (glob)
@@ -1795,7 +1790,6 @@  putting v1 shelvedstate file in place of
   continue: hg unshelve --continue
 mercurial does not crash
   $ hg unshelve --continue
-  rebasing 2:003d2d94241c "changes to: root" (tip)
   unshelve of 'ashelve' complete
   $ cd ..