D5742: histedit: add templating support to histedit's rule file generation

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Tue Jan 29 19:53:14 EST 2019


durin42 updated this revision to Diff 13565.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5742?vs=13564&id=13565

REVISION DETAIL
  https://phab.mercurial-scm.org/D5742

AFFECTED FILES
  hgext/histedit.py
  tests/test-histedit-commute.t

CHANGE DETAILS

diff --git a/tests/test-histedit-commute.t b/tests/test-histedit-commute.t
--- a/tests/test-histedit-commute.t
+++ b/tests/test-histedit-commute.t
@@ -76,6 +76,31 @@
   #  r, roll = like fold, but discard this commit's description and date
   #
 
+test customization of revision summary
+  $ HGEDITOR=cat hg histedit 177f92b77385 \
+  >  --config histedit.summary-format='I am rev {rev} desc {desc} tags {tags}'
+  pick 177f92b77385 I am rev 2 desc c tags 
+  pick 055a42cdd887 I am rev 3 desc d tags 
+  pick e860deea161a I am rev 4 desc e tags 
+  pick 652413bf663e I am rev 5 desc f tags tip
+  
+  # Edit history between 177f92b77385 and 652413bf663e
+  #
+  # Commits are listed from least to most recent
+  #
+  # You can reorder changesets by reordering the lines
+  #
+  # Commands:
+  #
+  #  e, edit = use commit, but stop for amending
+  #  m, mess = edit commit message without changing commit content
+  #  p, pick = use commit
+  #  b, base = checkout changeset and apply further changesets from there
+  #  d, drop = remove commit from history
+  #  f, fold = use commit, but combine it with the one above
+  #  r, roll = like fold, but discard this commit's description and date
+  #
+
 edit the history
 (use a hacky editor to check histedit-last-edit.txt backup)
 
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -156,6 +156,15 @@
   [histedit]
   linelen = 120      # truncate rule lines at 120 characters
 
+The summary of a change can be customized as well::
+
+  [histedit]
+  summary-format = '{rev} {bookmarks} {desc|firstline}'
+
+The customized summary should be kept short enough that rule lines
+will fit in the configured line length. See above if that requires
+customization.
+
 ``hg histedit`` attempts to automatically choose an appropriate base
 revision to use. To change which base revision is used, define a
 revset in your configuration file::
@@ -206,6 +215,7 @@
     error,
     exchange,
     extensions,
+    formatter,
     hg,
     logcmdutil,
     merge as mergemod,
@@ -217,6 +227,7 @@
     repair,
     scmutil,
     state as statemod,
+    templatekw,
     util,
 )
 from mercurial.utils import (
@@ -248,6 +259,8 @@
 configitem('ui', 'interface.histedit',
     default=None,
 )
+configitem('histedit', 'summary-format',
+           default='{rev} {desc|firstline}')
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -480,8 +493,13 @@
         <hash> <rev> <summary>
         """
         ctx = self.repo[self.node]
-        summary = _getsummary(ctx)
-        line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary)
+        ui = self.repo.ui
+        tres = formatter.templateresources(ui, self.repo)
+        t = formatter.maketemplater(ui, ui.config('histedit', 'summary-format'),
+                                    defaults=templatekw.keywords,
+                                    resources=tres)
+        summary = t.renderdefault({'ctx': ctx}).splitlines()[0]
+        line = '%s %s %s' % (self.verb, ctx, 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')



To: durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list