Mercurial > hg-stable
changeset 41523:11c076786d56
histedit: add templating support to histedit's rule file generation
This will allow users to customize the display of the rule list for the
free-form segment that we don't interpret. We've had users want to add things
like bookmark names or similar to the rule list as a convenience, which seems
reasonable.
Differential Revision: https://phab.mercurial-scm.org/D5742
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 29 Jan 2019 18:46:11 -0500 |
parents | b0865b5919c6 |
children | faa49a5914bb |
files | hgext/histedit.py tests/test-histedit-commute.t |
diffstat | 2 files changed, 53 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/histedit.py Fri Feb 01 17:03:51 2019 -0800 +++ b/hgext/histedit.py Tue Jan 29 18:46:11 2019 -0500 @@ -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-template = '{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:: @@ -248,6 +257,8 @@ configitem('ui', 'interface.histedit', default=None, ) +configitem('histedit', 'summary-template', + 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 +491,11 @@ <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 + summary = cmdutil.rendertemplate( + ctx, ui.config('histedit', 'summary-template')) or '' + summary = summary.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')
--- a/tests/test-histedit-commute.t Fri Feb 01 17:03:51 2019 -0800 +++ b/tests/test-histedit-commute.t Tue Jan 29 18:46:11 2019 -0500 @@ -52,6 +52,7 @@ summary: a + show the edit commands offered $ HGEDITOR=cat hg histedit 177f92b77385 pick 177f92b77385 2 c @@ -76,6 +77,33 @@ # 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-template='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) @@ -142,6 +170,7 @@ summary: a + put things back $ hg histedit 177f92b77385 --commands - 2>&1 << EOF | fixbundle @@ -184,6 +213,7 @@ summary: a + slightly different this time $ hg histedit 177f92b77385 --commands - << EOF 2>&1 | fixbundle @@ -225,6 +255,7 @@ summary: a + keep prevents stripping dead revs $ hg histedit 799205341b6b --keep --commands - 2>&1 << EOF | fixbundle > pick 799205341b6b d @@ -276,6 +307,7 @@ summary: a + try with --rev $ hg histedit --commands - --rev -2 2>&1 <<EOF | fixbundle > pick de71b079d9ce e @@ -326,6 +358,7 @@ date: Thu Jan 01 00:00:00 1970 +0000 summary: a + Verify that revsetalias entries work with histedit: $ cat >> $HGRCPATH <<EOF > [revsetalias] @@ -355,6 +388,7 @@ # r, roll = like fold, but discard this commit's description and date # + should also work if a commit message is missing $ BUNDLE="$TESTDIR/missing-comment.hg" $ hg init missing @@ -384,6 +418,7 @@ date: Mon Nov 28 16:35:28 2011 +0000 summary: Checked in text file + $ hg histedit 0 $ cd .. @@ -440,6 +475,7 @@ @@ -0,0 +1,1 @@ +changed + $ hg --config diff.git=yes export 1 # HG changeset patch # User test @@ -453,6 +489,7 @@ rename from another-dir/initial-file rename to another-dir/renamed-file + $ cd .. Test that branches are preserved and stays active