Patchwork [1,of,2,evolve-ext-V5] evolve: add new method _evolvecontinue (issue4854)

login
register
mail settings
Submitter Shusen LIU
Date Jan. 27, 2016, 12:14 a.m.
Message ID <53915488b7d05a88c09c.1453853664@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12893/
State Deferred
Delegated to: Pierre-Yves David
Headers show

Comments

Shusen LIU - Jan. 27, 2016, 12:14 a.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1453333539 28800
#      Wed Jan 20 15:45:39 2016 -0800
# Node ID 53915488b7d05a88c09cc807f90f03e9df7efadc
# Parent  abc82c98950bb662c4587fb80992a1cee875fd99
evolve: add new method _evolvecontinue (issue4854)

This patch introduces new method _evolvecontinue to for `hg evolve --continue`,
get rip of previous implmentation which calls `graft` command. It reads/writes
to `evolvestate` file for states.
timeless - Jan. 27, 2016, 1:48 a.m.
Shusen LIU wrote:
> get rip of previous implmentation

`rid` and `implementation`

A spell checker should be able to complain about the latter (Edge
automatically corrected it), a grammar checker (such as MS Word)
should probably be able to complain about that former.
Pierre-Yves David - Jan. 30, 2016, 3:56 p.m.
On 01/27/2016 01:14 AM, Shusen LIU wrote:
> # HG changeset patch
> # User Shusen LIU <liushusen@fb.com>
> # Date 1453333539 28800
> #      Wed Jan 20 15:45:39 2016 -0800
> # Node ID 53915488b7d05a88c09cc807f90f03e9df7efadc
> # Parent  abc82c98950bb662c4587fb80992a1cee875fd99
> evolve: add new method _evolvecontinue (issue4854)

Please refrain from sending series that use the new evolve state file 
until this new state file is in.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -112,6 +112,7 @@ 
 from mercurial import wireproto
 from mercurial import localrepo
 from mercurial.hgweb import hgweb_mod
+from mercurial.lock import release
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -952,6 +953,10 @@ 
         try:
             r = _evolvemerge(repo, orig, dest, pctx, keepbranch)
             if r[-1]:  #some conflict
+                _evolvestatewrite(repo, {'orig': orig.hex(),
+                                         'dest': dest.hex(),
+                                         'commitmsg': commitmsg,
+                                        })
                 raise error.Abort(
                         'unresolved merge conflicts (see hg help resolve)')
             nodenew = _relocatecommit(repo, orig, commitmsg)
@@ -968,6 +973,7 @@ 
             raise
         oldbookmarks = repo.nodebookmarks(nodesrc)
         _finalizerelocate(repo, orig, dest, nodenew, tr)
+        _evolvestatedelete(repo)
         tr.close()
     finally:
         tr.release()
@@ -1651,8 +1657,8 @@ 
             raise error.Abort('cannot specify both "--any" and "--continue"')
         if allopt:
             raise error.Abort('cannot specify both "--all" and "--continue"')
-        graftcmd = commands.table['graft'][0]
-        return graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
+        _evolvecontinue(repo)
+        return 0
     cmdutil.bailifchanged(repo)
 
 
@@ -1796,7 +1802,6 @@ 
         try:
             relocate(repo, orig, target, pctx, keepbranch)
         except MergeFailure:
-            repo.opener.write('graftstate', orig.hex() + '\n')
             repo.ui.write_err(_('evolve failed!\n'))
             repo.ui.write_err(
                 _('fix conflict and run "hg evolve --continue"'
@@ -3667,13 +3672,21 @@ 
                       _helploader))
         help.helptable.sort()
 
-def _relocatecommit(repo, orig, commitmsg):
+def _relocatecommit(repo, orig, commitmsg, continued=False):
     if commitmsg is None:
         commitmsg = orig.description()
-    extra = dict(orig.extra())
+    extra = orig.extra().copy()
     if 'branch' in extra:
         del extra['branch']
-    extra['rebase_source'] = orig.hex()
+
+    if continued:
+        source = extra.get('source')
+        if source:
+            extra['intermediate-source'] = orig.hex()
+        else:
+            extra['source'] = orig.hex()
+    else:
+        extra['rebase_source'] = orig.hex()
 
     backup = repo.ui.backupconfig('phases', 'new-commit')
     try:
@@ -3766,3 +3779,29 @@ 
 
 def _evolvestatedelete(repo):
     util.unlinkpath(repo.join('evolvestate'), ignoremissing=True)
+
+def _evolvecontinue(repo):
+    state = _evolvestateread(repo)
+    orig = repo[state['orig']]
+    dest = repo[state['dest']]
+    commitmsg = state['commitmsg']
+
+    desc = '%d:%s "%s"' % (orig.rev(), orig,
+                           orig.description().split('\n', 1)[0])
+    names = repo.nodetags(orig.node()) + repo.nodebookmarks(orig.node())
+    if names:
+        desc += ' (%s)' % ' '.join(names)
+    repo.ui.status(_('evolving %s\n') % desc)
+
+    wlock = lock = None
+    try:
+        wlock = repo.wlock() # must come first
+        lock = repo.lock()
+        tr = repo.transaction("evolvecontinue")
+        # perform write operation
+        nodenew = _relocatecommit(repo, orig, commitmsg, True)
+        _finalizerelocate(repo, orig, dest, nodenew, tr)
+        _evolvestatedelete(repo)
+        tr.close()
+    finally:
+        release(tr, lock, wlock) # reverse order
diff --git a/tests/test-stabilize-conflict.t b/tests/test-stabilize-conflict.t
--- a/tests/test-stabilize-conflict.t
+++ b/tests/test-stabilize-conflict.t
@@ -166,7 +166,7 @@ 
   $ hg resolve --all -m
   (no more unresolved files)
   $ hg evolve --continue
-  grafting 5:71c18f70c34f "babar count up to fifteen"
+  evolving 5:71c18f70c34f "babar count up to fifteen"
   $ hg resolve -l
   $ hg log -G
   @  changeset:   8:7f3d9db50b5d
diff --git a/tests/test-stabilize-result.t b/tests/test-stabilize-result.t
--- a/tests/test-stabilize-result.t
+++ b/tests/test-stabilize-result.t
@@ -97,13 +97,13 @@ 
   +a
   +newer a
   $ hg evolve --continue
-  grafting 5:3655f0f50885 "newer a"
+  evolving 5:3655f0f50885 "newer a"
   abort: unresolved merge conflicts (see "hg help resolve")
   [255]
   $ hg resolve -m a
   (no more unresolved files)
   $ hg evolve --continue
-  grafting 5:3655f0f50885 "newer a"
+  evolving 5:3655f0f50885 "newer a"
 
 Stabilize latecomer with different parent
 =========================================