changeset 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 c4fc33c477da
files hgext/histedit.py tests/test-histedit-arguments.t
diffstat 2 files changed, 33 insertions(+), 11 deletions(-) [+]
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'
--- a/tests/test-histedit-arguments.t	Fri May 27 14:03:00 2016 -0700
+++ b/tests/test-histedit-arguments.t	Tue Jun 21 14:58:49 2016 -0700
@@ -507,17 +507,15 @@
   $ 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
@@ -528,11 +526,12 @@
 
 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
   #