[PATCH 09 of 25 RFC] shelve: directly handle the initial parent alignment

Boris Feld boris.feld at octobus.net
Thu Jun 7 10:11:08 EDT 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1527546650 -7200
#      Tue May 29 00:30:50 2018 +0200
# Node ID 90880b80466bb6ec839c0dd913f2a413abede4cc
# Parent  ade0ce417ac654814fa0eda21637933f262ceac0
# EXP-Topic graftshelve
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 90880b80466b
shelve: directly handle the initial parent alignment

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.

After this change, we no longer need to use rebase in shelve.

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

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -686,6 +686,10 @@ def unshelvecontinue(ui, repo, state, op
         shelvectx = repo[state.parents[1]]
         pendingctx = state.pendingctx
 
+        with repo.dirstate.parentchange():
+            repo.setparents(state.pendingctx.node(), nodemod.nullid)
+            repo.dirstate.write(repo.currenttransaction())
+
         overrides = {('phases', 'new-commit'): phases.secret}
         with repo.ui.configoverride(overrides, 'unshelve'):
             with repo.dirstate.parentchange():
@@ -761,33 +765,46 @@ def _rebaserestoredcommit(ui, repo, opts
     if tmpwctx.node() == shelvectx.parents()[0].node():
         return shelvectx
 
-    ui.status(_('rebasing shelved changes\n'))
-    try:
-        rebase.rebase(ui, repo, **{
-            r'rev': [shelvectx.rev()],
-            r'dest': "%d" % tmpwctx.rev(),
-            r'keep': True,
-            r'tool': opts.get('tool', ''),
-        })
-    except error.InterventionRequired:
-        tr.close()
+    overrides = {
+        ('ui', 'forcemerge'): opts.get('tool', ''),
+        ('phases', 'new-commit'): phases.secret,
+    }
+    with repo.ui.configoverride(overrides, 'unshelve'):
+        ui.status(_('rebasing shelved changes\n'))
+        stats = merge.graft(repo, shelvectx, shelvectx.p1(),
+                           labels=['dest', 'source'],
+                           keepconflictparent=True)
+        if stats.unresolvedcount:
+            tr.close()
+
+            nodestoremove = [repo.changelog.node(rev)
+                             for rev in xrange(oldtiprev, len(repo))]
+            shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
+                              branchtorestore, opts.get('keep'), activebookmark)
+            raise error.InterventionRequired(
+                _("unresolved conflicts (see 'hg resolve', then "
+                  "'hg unshelve --continue')"))
 
-        nodestoremove = [repo.changelog.node(rev)
-                         for rev in xrange(oldtiprev, len(repo))]
-        shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove,
-                          branchtorestore, opts.get('keep'), activebookmark)
+        with repo.dirstate.parentchange():
+            repo.setparents(tmpwctx.node(), nodemod.nullid)
+            newnode = repo.commit(text=shelvectx.description(),
+                                  extra=shelvectx.extra(),
+                                  user=shelvectx.user(),
+                                  date=shelvectx.date())
 
-        repo.vfs.rename('rebasestate', 'unshelverebasestate')
-        raise error.InterventionRequired(
-            _("unresolved conflicts (see 'hg resolve', then "
-              "'hg unshelve --continue')"))
+        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 = tmpwctx
+            msg = _('note: unshelved changes already existed '
+                    'in the working copy\n')
+            ui.status(msg)
+        else:
+            shelvectx = repo[newnode]
+            hg.updaterepo(repo, tmpwctx.node(), False)
 
-    # refresh ctx after rebase completes
-    shelvectx = repo['tip']
-
-    if tmpwctx not in shelvectx.parents():
-        # rebase was a no-op, so it produced no child commit
-        shelvectx = tmpwctx
     return shelvectx
 
 def _forgetunknownfiles(repo, shelvectx, addedbefore):
diff --git a/tests/test-copytrace-heuristics.t b/tests/test-copytrace-heuristics.t
--- a/tests/test-copytrace-heuristics.t
+++ b/tests/test-copytrace-heuristics.t
@@ -583,7 +583,6 @@ Test shelve/unshelve
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 2:45f63161acea "changes to: initial" (tip)
   merging b and a to b
   $ ls
   b
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -213,7 +213,6 @@ local edits should not prevent a shelved
   unshelving change 'default-01'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 4:32c69314e062 "changes to: [mq]: second.patch" (tip)
   merging a/a
 
   $ hg revert --all -q
@@ -335,7 +334,6 @@ force a conflicted merge to occur
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 5:32c69314e062 "changes to: [mq]: second.patch" (tip)
   merging a/a
   warning: conflicts while merging a/a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -529,7 +527,6 @@ if we resolve a conflict while unshelvin
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 6:2f694dd83a13 "changes to: second" (tip)
   merging a/a
   $ hg parents -q
   4:33f7f61e6c5e
@@ -552,9 +549,8 @@ if we resolve a conflict while unshelvin
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 6:2f694dd83a13 "changes to: second" (tip)
   merging a/a
-  note: rebase of 6:2f694dd83a13 created no changes to commit
+  note: unshelved changes already existed in the working copy
   $ hg parents -q
   4:33f7f61e6c5e
   $ hg shelve -l
@@ -643,7 +639,6 @@ shelve should leave dirstate clean (issu
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 4:82a0d7d6ba61 "changes to: xyz" (tip)
   $ hg status
   M z
 
@@ -670,7 +665,6 @@ shelve should only unshelve pending chan
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 3:958bcbd1776e "changes to: c" (tip)
   $ hg status
   A d
 
@@ -684,7 +678,6 @@ unshelve should work on an ancestor of t
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 3:013284d9655e "changes to: b" (tip)
   $ hg status
   A d
 
@@ -786,7 +779,6 @@ unshelve and conflicts with tracked and 
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 5:81152db69da7 "changes to: commit stuff" (tip)
   merging f
   warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -825,7 +817,6 @@ unshelve and conflicts with tracked and 
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 5:81152db69da7 "changes to: commit stuff" (tip)
   $ hg st
   M a
   A f
@@ -841,7 +832,6 @@ unshelve and conflicts with tracked and 
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 5:81152db69da7 "changes to: commit stuff" (tip)
   merging f
   warning: conflicts while merging f! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -883,7 +873,6 @@ Recreate some conflict again
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 5:e42a7da90865 "changes to: second" (tip)
   merging a/a
   warning: conflicts while merging a/a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -993,7 +982,6 @@ Test interactive shelve
   unshelving change 'test'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 6:96a1354f65f6 "changes to: create conflict" (tip)
   merging a/a
   $ hg bookmark
    * test                      4:33f7f61e6c5e
@@ -1170,13 +1158,12 @@ Test visibility of in-memory changes ins
   $ hg unshelve --keep default
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 7:206bf5d4f922 "changes to: create conflict" (tip)
   ==== preupdate:
   VISIBLE 6:66b86db80ee4
   ACTUAL  5:703117a2acfb
   ====
   ==== preupdate:
-  VISIBLE 8:a0e04704317e
+  VISIBLE 8:92fdbb7b4de7
   ACTUAL  5:703117a2acfb
   ====
   ==== preupdate:
@@ -1215,7 +1202,6 @@ Test visibility of in-memory changes ins
   $ hg unshelve --keep default
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 7:206bf5d4f922 "changes to: create conflict" (tip)
   ==== update:
   VISIBLE 6:66b86db80ee4
   VISIBLE 7:206bf5d4f922
@@ -1355,7 +1341,6 @@ If I shelve, add the file, and unshelve,
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 1:098df96e7410 "(changes in empty repository)" (tip)
   merging unknown
   $ hg status
   A unknown
@@ -1376,7 +1361,6 @@ And if I shelve, commit, then unshelve, 
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 1:098df96e7410 "(changes in empty repository)" (tip)
   merging unknown
   $ hg status
   M unknown
@@ -1509,7 +1493,6 @@ will be preserved.
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 2:425c97ef07f3 "changes to: a" (tip)
   merging a
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -1544,7 +1527,6 @@ test branch.
   $ hg unshelve
   unshelving change 'test'
   rebasing shelved changes
-  rebasing 2:357525f34729 "changes to: test-commit" (tip)
   $ hg status
   A b
   $ hg branch
@@ -1585,7 +1567,6 @@ shelve on new branch, conflict with prev
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
   rebasing shelved changes
-  rebasing 2:425c97ef07f3 "changes to: a" (tip)
   merging a
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -1658,7 +1639,6 @@ Prepare unshelve with a corrupted shelve
   $ hg unshelve
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 1:396ea74229f9 "(changes in empty repository)" (tip)
   merging file
   warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -1697,7 +1677,6 @@ Unshelve respects --keep even if user in
   $ hg unshelve --keep
   unshelving change 'default'
   rebasing shelved changes
-  rebasing 2:3fbe6fbb0bef "changes to: 1" (tip)
   merging file
   warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
@@ -1755,7 +1734,6 @@ New versions of Mercurial know how to re
   $ hg unshelve
   unshelving change 'ashelve'
   rebasing shelved changes
-  rebasing 2:003d2d94241c "changes to: root" (tip)
   merging a
   warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
   unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')


More information about the Mercurial-devel mailing list