Mercurial > public > mercurial-scm > hg-stable
diff hgext/histedit.py @ 29470:2ff243c415b4
histedit: move autoverb rule to the commit it matches
Inspired by how 'git rebase -i' works, we move the autoverb to the
commit line summary that it matches. We do this by iterating over all
rules and inserting each non-autoverb line into a key in an ordered
dictionary. If we find an autoverb line later, we then search for the
matching key and append it to the list (which is the value of each key
in the dictionary). If we can't find a previous line to move to, then we
leave the rule in the same spot.
Tests have been updated but the diff looks a little messy because we
need to change one of the summary lines so that it will actually move to
a new spot. On top of that, we added -q flags to future some of the
output and needed to change the file it modified so that it wouldn't
cause a conflict.
author | Sean Farley <sean@farley.io> |
---|---|
date | Tue, 21 Jun 2016 14:58:49 -0700 |
parents | ffa194c3a83c |
children | e1a4015f5e34 |
line wrap: on
line diff
--- a/hgext/histedit.py Fri May 27 14:03:00 2016 -0700 +++ b/hgext/histedit.py Tue Jun 21 14:58:49 2016 -0700 @@ -1316,15 +1316,38 @@ 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'