Patchwork [1,of,6,V2] histedit: move autoverb logic from torule to ruleeditor

login
register
mail settings
Submitter Sean Farley
Date June 30, 2016, 9:58 p.m.
Message ID <fc14954300177abfd863.1467323930@laptop.office.atlassian.com>
Download mbox | patch
Permalink /patch/15696/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Sean Farley - June 30, 2016, 9:58 p.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1464306370 25200
#      Thu May 26 16:46:10 2016 -0700
# Node ID fc14954300177abfd86358903adf37cd74ba2bfd
# Parent  aa1d56003872cba207d908706da059141dd901a5
# EXP-Topic autoverb
histedit: move autoverb logic from torule to ruleeditor

This is needed for an upcoming change that will automatically rearrange the
rules based on the commit message. Before this patch, the autoverb logic only
applied to one rule at a time. This moves that logic one step up so that it can
iterate over all the rules and rearrange as needed.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -421,18 +421,10 @@  class histeditaction(object):
         """
         ctx = self.repo[self.node]
         summary = ''
         if ctx.description():
             summary = ctx.description().splitlines()[0]
-
-        fword = summary.split(' ', 1)[0].lower()
-        # if it doesn't end with the special character '!' just skip this
-        if (self.repo.ui.configbool("experimental", "histedit.autoverb") and
-            initial and fword.endswith('!')):
-            fword = fword[:-1]
-            if fword in primaryactions | secondaryactions | tertiaryactions:
-                self.verb = fword
         line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary)
         # trim to 75 columns by default so it's not stupidly wide in my editor
         # (the 5 more are left for verb)
         maxlen = self.repo.ui.configint('histedit', 'linelen', default=80)
         maxlen = max(maxlen, 22) # avoid truncating hash
@@ -1315,10 +1307,24 @@  def between(repo, old, new, keep):
 def ruleeditor(repo, ui, actions, editcomment=""):
     """open an editor to edit rules
 
     rules are in the format [ [act, ctx], ...] like in state.rules
     """
+    if repo.ui.configbool("experimental", "histedit.autoverb"):
+        for act in actions:
+            ctx = repo[act.node]
+            summary = ''
+            if ctx.description():
+                summary = ctx.description().splitlines()[0]
+
+            fword = summary.split(' ', 1)[0].lower()
+            # 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
+
     rules = '\n'.join([act.torule(initial=True) for act in actions])
     rules += '\n\n'
     rules += editcomment
     rules = ui.edit(rules, ui.username(), {'prefix': 'histedit'})