Patchwork [6,of,6] histedit: move autoverb rule to the commit it matches

login
register
mail settings
Submitter Sean Farley
Date June 21, 2016, 11:32 p.m.
Message ID <da7ee04f9d62e23cc27f.1466551966@laptop.local>
Download mbox | patch
Permalink /patch/15571/
State Changes Requested
Headers show

Comments

Sean Farley - June 21, 2016, 11:32 p.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1466546329 25200
#      Tue Jun 21 14:58:49 2016 -0700
# Node ID da7ee04f9d62e23cc27fe9537b0a4d47aa03da8b
# Parent  6459e0be7633c075e61017f2eab9f41a3d21f5e8
# EXP-Topic autoverb
histedit: move autoverb rule to the commit it matches

Similar to how git rebase -i works, we move the autoverb to the commit line
summary that it matches.

Tests have been updated.
Simon Farnsworth - June 28, 2016, 2:01 p.m.
Apart from the test suite changes, this LGTM.

On 22/06/2016 00:32, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean@farley.io>
> # Date 1466546329 25200
> #      Tue Jun 21 14:58:49 2016 -0700
> # Node ID da7ee04f9d62e23cc27fe9537b0a4d47aa03da8b
> # Parent  6459e0be7633c075e61017f2eab9f41a3d21f5e8
> # EXP-Topic autoverb
> histedit: move autoverb rule to the commit it matches
>
> Similar to how git rebase -i works, we move the autoverb to the commit line
> summary that it matches.
>
> Tests have been updated.
>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -1314,19 +1314,42 @@ def ruleeditor(repo, ui, actions, editco
>       """open an editor to edit rules
>
>       rules are in the format [ [act, ctx], ...] like in state.rules
>       """
>       if repo.ui.configbool("experimental", "histedit.autoverb"):
> +        newact = util.sortdict()
>           for act in actions:
>               ctx = repo[act.node]
>               summary = _getsummary(ctx)
>               fword = summary.split(' ', 1)[0].lower()
> +            added = False
> +
>               # if it doesn't end with the special character '!' just skip this
>               if fword.endswith('!'):
>                   fword = fword[:-1]
>                   if fword in primaryactions | secondaryactions | tertiaryactions:
>                       act.verb = fword
> +                    # get the target summary
> +                    tsum = summary[len(fword) + 1:].lstrip()
> +                    # safe but slow: reverse iterate over the actions so we
> +                    # don't clash on two commits having the same summary
> +                    for na, l in reversed(list(newact.iteritems())):
> +                        actx = repo[na.node]
> +                        asum = _getsummary(actx)
> +                        if asum == tsum:
> +                            added = True
> +                            l.append(act)
> +                            break
> +
> +            if not added:
> +                newact[act] = []
> +
> +        # copy over and flatten the new list
> +        actions = []
> +        for na, l in newact.iteritems():
> +            actions.append(na)
> +            actions += l
>
>       rules = '\n'.join([act.torule() for act in actions])
>       rules += '\n\n'
>       rules += editcomment
>       rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'})
> diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
> --- a/tests/test-histedit-arguments.t
> +++ b/tests/test-histedit-arguments.t
> @@ -505,36 +505,35 @@ amend should not be blocked by the ongoi
>   Test autoverb feature
>
>     $ hg init autoverb
>     $ cd autoverb
>     $ echo alpha >> alpha
> -  $ hg addr
> -  adding alpha
> -  $ hg ci -m one
> +  $ hg ci -qAm one
>     $ echo alpha >> alpha
> -  $ hg ci -m two
> -  $ echo alpha >> alpha
> -  $ hg ci -m "roll! three"
> +  $ hg ci -qm two
> +  $ echo beta >> beta
> +  $ hg ci -qAm "roll! one"
>

Why these changes? They don't seem to match up to the main thrust of the 
patchset?

>     $ hg log --style compact --graph
> -  @  2[tip]   1b0b0b04c8fe   1970-01-01 00:00 +0000   test
> -  |    roll! three
> +  @  2[tip]   4f34d0f8b5fa   1970-01-01 00:00 +0000   test
> +  |    roll! one
>     |
>     o  1   579e40513370   1970-01-01 00:00 +0000   test
>     |    two
>     |
>     o  0   6058cbb6cfd7   1970-01-01 00:00 +0000   test
>          one
>
>
>   Check that 'roll' is selected by default
>
> -  $ HGEDITOR=cat hg histedit 1 --config experimental.histedit.autoverb=True
> +  $ HGEDITOR=cat hg histedit 0 --config experimental.histedit.autoverb=True
> +  pick 6058cbb6cfd7 0 one
> +  roll 4f34d0f8b5fa 2 roll! one
>     pick 579e40513370 1 two
> -  roll 1b0b0b04c8fe 2 roll! three
>
> -  # Edit history between 579e40513370 and 1b0b0b04c8fe
> +  # Edit history between 6058cbb6cfd7 and 4f34d0f8b5fa
>     #
>     # Commits are listed from least to most recent
>     #
>     # You can reorder changesets by reordering the lines
>     #
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=mEgSWILcY4c4W3zjApBQLA&m=XJgnLgmqvd94zZ4Gg-23pLKb0FquyX6LtDveEumutfQ&s=a8SR2qtk9k2ewYmNYbYAw0bTnJMD9r2BkThX1bhXJwI&e=
>
Sean Farley - June 28, 2016, 8:24 p.m.
Simon Farnsworth <simonfar@fb.com> writes:

> Apart from the test suite changes, this LGTM.
>
> On 22/06/2016 00:32, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean@farley.io>
>> # Date 1466546329 25200
>> #      Tue Jun 21 14:58:49 2016 -0700
>> # Node ID da7ee04f9d62e23cc27fe9537b0a4d47aa03da8b
>> # Parent  6459e0be7633c075e61017f2eab9f41a3d21f5e8
>> # EXP-Topic autoverb
>> histedit: move autoverb rule to the commit it matches
>>
>> Similar to how git rebase -i works, we move the autoverb to the commit line
>> summary that it matches.
>>
>> Tests have been updated.
>>
>> diff --git a/hgext/histedit.py b/hgext/histedit.py
>> --- a/hgext/histedit.py
>> +++ b/hgext/histedit.py
>> @@ -1314,19 +1314,42 @@ def ruleeditor(repo, ui, actions, editco
>>       """open an editor to edit rules
>>
>>       rules are in the format [ [act, ctx], ...] like in state.rules
>>       """
>>       if repo.ui.configbool("experimental", "histedit.autoverb"):
>> +        newact = util.sortdict()
>>           for act in actions:
>>               ctx = repo[act.node]
>>               summary = _getsummary(ctx)
>>               fword = summary.split(' ', 1)[0].lower()
>> +            added = False
>> +
>>               # if it doesn't end with the special character '!' just skip this
>>               if fword.endswith('!'):
>>                   fword = fword[:-1]
>>                   if fword in primaryactions | secondaryactions | tertiaryactions:
>>                       act.verb = fword
>> +                    # get the target summary
>> +                    tsum = summary[len(fword) + 1:].lstrip()
>> +                    # safe but slow: reverse iterate over the actions so we
>> +                    # don't clash on two commits having the same summary
>> +                    for na, l in reversed(list(newact.iteritems())):
>> +                        actx = repo[na.node]
>> +                        asum = _getsummary(actx)
>> +                        if asum == tsum:
>> +                            added = True
>> +                            l.append(act)
>> +                            break
>> +
>> +            if not added:
>> +                newact[act] = []
>> +
>> +        # copy over and flatten the new list
>> +        actions = []
>> +        for na, l in newact.iteritems():
>> +            actions.append(na)
>> +            actions += l
>>
>>       rules = '\n'.join([act.torule() for act in actions])
>>       rules += '\n\n'
>>       rules += editcomment
>>       rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'})
>> diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
>> --- a/tests/test-histedit-arguments.t
>> +++ b/tests/test-histedit-arguments.t
>> @@ -505,36 +505,35 @@ amend should not be blocked by the ongoi
>>   Test autoverb feature
>>
>>     $ hg init autoverb
>>     $ cd autoverb
>>     $ echo alpha >> alpha
>> -  $ hg addr
>> -  adding alpha
>> -  $ hg ci -m one
>> +  $ hg ci -qAm one
>>     $ echo alpha >> alpha
>> -  $ hg ci -m two
>> -  $ echo alpha >> alpha
>> -  $ hg ci -m "roll! three"
>> +  $ hg ci -qm two
>> +  $ echo beta >> beta
>> +  $ hg ci -qAm "roll! one"
>>
>
> Why these changes? They don't seem to match up to the main thrust of the 
> patchset?

They're needed to use this feature which is "verb! some previous
commit's summary." So, in this case I needed to change "roll! three" to
"roll! one" so that it actually moves the commit one line up. The '-q's
were added to future-proof the output.

>>     $ hg log --style compact --graph
>> -  @  2[tip]   1b0b0b04c8fe   1970-01-01 00:00 +0000   test
>> -  |    roll! three
>> +  @  2[tip]   4f34d0f8b5fa   1970-01-01 00:00 +0000   test
>> +  |    roll! one
>>     |
>>     o  1   579e40513370   1970-01-01 00:00 +0000   test
>>     |    two
>>     |
>>     o  0   6058cbb6cfd7   1970-01-01 00:00 +0000   test
>>          one
>>
>>
>>   Check that 'roll' is selected by default
>>
>> -  $ HGEDITOR=cat hg histedit 1 --config experimental.histedit.autoverb=True
>> +  $ HGEDITOR=cat hg histedit 0 --config experimental.histedit.autoverb=True
>> +  pick 6058cbb6cfd7 0 one
>> +  roll 4f34d0f8b5fa 2 roll! one
>>     pick 579e40513370 1 two
>> -  roll 1b0b0b04c8fe 2 roll! three
>>
>> -  # Edit history between 579e40513370 and 1b0b0b04c8fe
>> +  # Edit history between 6058cbb6cfd7 and 4f34d0f8b5fa
>>     #
>>     # Commits are listed from least to most recent
>>     #
>>     # You can reorder changesets by reordering the lines
>>     #
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@mercurial-scm.org
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=mEgSWILcY4c4W3zjApBQLA&m=XJgnLgmqvd94zZ4Gg-23pLKb0FquyX6LtDveEumutfQ&s=a8SR2qtk9k2ewYmNYbYAw0bTnJMD9r2BkThX1bhXJwI&e=

What the what??
Simon Farnsworth - June 28, 2016, 8:31 p.m.
On 28/06/2016 21:24, Sean Farley wrote:
> Simon Farnsworth <simonfar@fb.com> writes:
>
>> Apart from the test suite changes, this LGTM.

And with Sean's explanation of the changes, I think this is good to go.

<snip>

>>> diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
>>> --- a/tests/test-histedit-arguments.t
>>> +++ b/tests/test-histedit-arguments.t
>>> @@ -505,36 +505,35 @@ amend should not be blocked by the ongoi
>>>    Test autoverb feature
>>>
>>>      $ hg init autoverb
>>>      $ cd autoverb
>>>      $ echo alpha >> alpha
>>> -  $ hg addr
>>> -  adding alpha
>>> -  $ hg ci -m one
>>> +  $ hg ci -qAm one
>>>      $ echo alpha >> alpha
>>> -  $ hg ci -m two
>>> -  $ echo alpha >> alpha
>>> -  $ hg ci -m "roll! three"
>>> +  $ hg ci -qm two
>>> +  $ echo beta >> beta
>>> +  $ hg ci -qAm "roll! one"
>>>
>>
>> Why these changes? They don't seem to match up to the main thrust of the
>> patchset?
>
> They're needed to use this feature which is "verb! some previous
> commit's summary." So, in this case I needed to change "roll! three" to
> "roll! one" so that it actually moves the commit one line up. The '-q's
> were added to future-proof the output.
>

I see; I would have expected you to simply change the message on the 
third commit from "roll! three" to "roll! one", but the other edits make 
sense and bring it more in line with other tests.

<snip>

>>> _______________________________________________
>>> Mercurial-devel mailing list
>>> Mercurial-devel@mercurial-scm.org
>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=mEgSWILcY4c4W3zjApBQLA&m=XJgnLgmqvd94zZ4Gg-23pLKb0FquyX6LtDveEumutfQ&s=a8SR2qtk9k2ewYmNYbYAw0bTnJMD9r2BkThX1bhXJwI&e=
>
> What the what??
>
The combination of Thunderbird and corporate Exchange set up to mangle 
all incoming URLs leads to "interesting" lines from time to time. Big 
company problems...

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1314,19 +1314,42 @@  def ruleeditor(repo, ui, actions, editco
     """open an editor to edit rules
 
     rules are in the format [ [act, ctx], ...] like in state.rules
     """
     if repo.ui.configbool("experimental", "histedit.autoverb"):
+        newact = util.sortdict()
         for act in actions:
             ctx = repo[act.node]
             summary = _getsummary(ctx)
             fword = summary.split(' ', 1)[0].lower()
+            added = False
+
             # if it doesn't end with the special character '!' just skip this
             if fword.endswith('!'):
                 fword = fword[:-1]
                 if fword in primaryactions | secondaryactions | tertiaryactions:
                     act.verb = fword
+                    # get the target summary
+                    tsum = summary[len(fword) + 1:].lstrip()
+                    # safe but slow: reverse iterate over the actions so we
+                    # don't clash on two commits having the same summary
+                    for na, l in reversed(list(newact.iteritems())):
+                        actx = repo[na.node]
+                        asum = _getsummary(actx)
+                        if asum == tsum:
+                            added = True
+                            l.append(act)
+                            break
+
+            if not added:
+                newact[act] = []
+
+        # copy over and flatten the new list
+        actions = []
+        for na, l in newact.iteritems():
+            actions.append(na)
+            actions += l
 
     rules = '\n'.join([act.torule() for act in actions])
     rules += '\n\n'
     rules += editcomment
     rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'})
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -505,36 +505,35 @@  amend should not be blocked by the ongoi
 Test autoverb feature
 
   $ hg init autoverb
   $ cd autoverb
   $ echo alpha >> alpha
-  $ hg addr
-  adding alpha
-  $ hg ci -m one
+  $ hg ci -qAm one
   $ echo alpha >> alpha
-  $ hg ci -m two
-  $ echo alpha >> alpha
-  $ hg ci -m "roll! three"
+  $ hg ci -qm two
+  $ echo beta >> beta
+  $ hg ci -qAm "roll! one"
 
   $ hg log --style compact --graph
-  @  2[tip]   1b0b0b04c8fe   1970-01-01 00:00 +0000   test
-  |    roll! three
+  @  2[tip]   4f34d0f8b5fa   1970-01-01 00:00 +0000   test
+  |    roll! one
   |
   o  1   579e40513370   1970-01-01 00:00 +0000   test
   |    two
   |
   o  0   6058cbb6cfd7   1970-01-01 00:00 +0000   test
        one
   
 
 Check that 'roll' is selected by default
 
-  $ HGEDITOR=cat hg histedit 1 --config experimental.histedit.autoverb=True
+  $ HGEDITOR=cat hg histedit 0 --config experimental.histedit.autoverb=True
+  pick 6058cbb6cfd7 0 one
+  roll 4f34d0f8b5fa 2 roll! one
   pick 579e40513370 1 two
-  roll 1b0b0b04c8fe 2 roll! three
   
-  # Edit history between 579e40513370 and 1b0b0b04c8fe
+  # Edit history between 6058cbb6cfd7 and 4f34d0f8b5fa
   #
   # Commits are listed from least to most recent
   #
   # You can reorder changesets by reordering the lines
   #