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

Sean Farley sean at farley.io
Tue Jun 28 16:24:52 EDT 2016


Simon Farnsworth <simonfar at 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 at 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 at 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??


More information about the Mercurial-devel mailing list