Patchwork [evolve-ext-V4] evolve: add new method _evolvecontinue (issue4854)

login
register
mail settings
Submitter Shusen LIU
Date Jan. 20, 2016, 11:46 p.m.
Message ID <9f9170b5e6761ca1e417.1453333585@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12854/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Shusen LIU - Jan. 20, 2016, 11:46 p.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1453333539 28800
#      Wed Jan 20 15:45:39 2016 -0800
# Node ID 9f9170b5e6761ca1e4175d1aafb9604e2cc59fdf
# Parent  d4aa50ecc5a334694d4cad45985fcec494337d87
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. 21, 2016, 1:22 a.m.
You should also touch cmdutil.afterresolvedstates

On Wed, Jan 20, 2016 at 6:46 PM, Shusen LIU <liushusen@fb.com> wrote:
> # HG changeset patch
> # User Shusen LIU <liushusen@fb.com>
> # Date 1453333539 28800
> #      Wed Jan 20 15:45:39 2016 -0800
> # Node ID 9f9170b5e6761ca1e4175d1aafb9604e2cc59fdf
> # Parent  d4aa50ecc5a334694d4cad45985fcec494337d87
> 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.
>
> 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:
> @@ -3764,3 +3777,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
>  =========================================
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Shusen LIU - Jan. 21, 2016, 2:58 p.m.
Can you please point out which file / which function you are referring to?
I tried `grep -rl afterresolvedstate` but didn't get any result.



On 1/21/16, 01:22, "timeless.bmo1@gmail.com on behalf of timeless" <timeless.bmo1@gmail.com on behalf of timeless@gmail.com> wrote:

>You should also touch cmdutil.afterresolvedstates

>

>On Wed, Jan 20, 2016 at 6:46 PM, Shusen LIU <liushusen@fb.com> wrote:

>> # HG changeset patch

>> # User Shusen LIU <liushusen@fb.com>

>> # Date 1453333539 28800

>> #      Wed Jan 20 15:45:39 2016 -0800

>> # Node ID 9f9170b5e6761ca1e4175d1aafb9604e2cc59fdf

>> # Parent  d4aa50ecc5a334694d4cad45985fcec494337d87

>> 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.

>>

>> 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:

>> @@ -3764,3 +3777,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

>>  =========================================

>> _______________________________________________

>> Mercurial-devel mailing list

>> Mercurial-devel@selenic.com

>> https://selenic.com/mailman/listinfo/mercurial-devel
timeless - Jan. 21, 2016, 7:05 p.m.
On Thu, Jan 21, 2016 at 9:58 AM, Shusen Liu <liushusen@fb.com> wrote:
> Can you please point out which file / which function you are referring to?
> I tried `grep -rl afterresolvedstate` but didn't get any result.

here's rebase hooking into this:
https://selenic.com/repo/hg/rev/157675d0f600
here's the underlying feature:
https://selenic.com/repo/hg/rev/d46db4390715

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:
@@ -3764,3 +3777,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
 =========================================