changeset 45793:96fcc37a9c80

rebase: make summary template configurable, with default to shared template Differential Revision: https://phab.mercurial-scm.org/D9251
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 22 Oct 2020 23:10:06 -0700
parents b4c193509cd0
children f90a5c211251
files hgext/rebase.py mercurial/cmdutil.py mercurial/configitems.py tests/test-rebase-templates.t
diffstat 4 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Thu Oct 22 22:29:22 2020 -0700
+++ b/hgext/rebase.py	Thu Oct 22 23:10:06 2020 -0700
@@ -34,7 +34,6 @@
     dirstateguard,
     error,
     extensions,
-    formatter,
     merge as mergemod,
     mergestate as mergestatemod,
     mergeutil,
@@ -52,7 +51,6 @@
     scmutil,
     smartset,
     state as statemod,
-    templatekw,
     util,
 )
 
@@ -153,7 +151,9 @@
         labels_spec,
         labels_spec,
     )
-    return cmdutil.rendertemplate(ctx, spec)
+    return cmdutil.format_changeset_summary(
+        ctx.repo().ui, ctx, command=b'rebase', default_spec=spec
+    )
 
 
 class rebaseruntime(object):
--- a/mercurial/cmdutil.py	Thu Oct 22 22:29:22 2020 -0700
+++ b/mercurial/cmdutil.py	Thu Oct 22 23:10:06 2020 -0700
@@ -1210,6 +1210,24 @@
     return t.renderdefault(mapping)
 
 
+def format_changeset_summary(ui, ctx, command=None, default_spec=None):
+    """Format a changeset summary (one line)."""
+    spec = None
+    if command:
+        spec = ui.config(
+            b'command-templates', b'oneline-summary.%s' % command, None
+        )
+    if not spec:
+        spec = ui.config(b'command-templates', b'oneline-summary')
+    if not spec:
+        spec = default_spec
+    if not spec:
+        # TODO: Pick a default we can agree on. This isn't used yet.
+        raise error.ProgrammingError(b"no default one-line summary defined yet")
+    text = rendertemplate(ctx, spec)
+    return text.split(b'\n')[0]
+
+
 def _buildfntemplate(pat, total=None, seqno=None, revwidth=None, pathname=None):
     r"""Convert old-style filename format string to template string
 
--- a/mercurial/configitems.py	Thu Oct 22 22:29:22 2020 -0700
+++ b/mercurial/configitems.py	Thu Oct 22 23:10:06 2020 -0700
@@ -251,6 +251,15 @@
     default=None,
     alias=[(b'ui', b'pre-merge-tool-output-template')],
 )
+coreconfigitem(
+    b'command-templates', b'oneline-summary', default=None,
+)
+coreconfigitem(
+    b'command-templates',
+    b'oneline-summary.*',
+    default=dynamicdefault,
+    generic=True,
+)
 _registerdiffopts(section=b'commands', configprefix=b'commit.interactive.')
 coreconfigitem(
     b'commands', b'commit.post-status', default=False,
--- a/tests/test-rebase-templates.t	Thu Oct 22 22:29:22 2020 -0700
+++ b/tests/test-rebase-templates.t	Thu Oct 22 23:10:06 2020 -0700
@@ -82,3 +82,21 @@
   o  0:18d04c59bb5d Added a
   
 
+Respects command-templates.oneline-summary
+
+  $ hg rebase -r 7 -d 8 -n --config command-templates.oneline-summary='rev: {rev}'
+  starting dry-run rebase; repository will not be changed
+  rebasing rev: 7
+  note: not rebasing rev: 7, its destination already has all its changes
+  dry-run rebase completed successfully; run without -n/--dry-run to perform this rebase
+
+
+command-templates.oneline-summary.rebase overrides
+
+  $ hg rebase -r 7 -d 8 -n \
+  > --config command-templates.oneline-summary='global: {rev}' \
+  > --config command-templates.oneline-summary.rebase='override: {rev}'
+  starting dry-run rebase; repository will not be changed
+  rebasing override: 7
+  note: not rebasing override: 7, its destination already has all its changes
+  dry-run rebase completed successfully; run without -n/--dry-run to perform this rebase