Patchwork D9251: rebase: make summary template configurable, with default to shared template

login
register
mail settings
Submitter phabricator
Date Oct. 27, 2020, 10:43 p.m.
Message ID <differential-rev-PHID-DREV-heuejwnuj5lcz25gc32h-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47522/
State Superseded
Headers show

Comments

phabricator - Oct. 27, 2020, 10:43 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/rebase.py
  mercurial/cmdutil.py
  mercurial/configitems.py
  tests/test-rebase-templates.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-rebase-templates.t b/tests/test-rebase-templates.t
--- a/tests/test-rebase-templates.t
+++ b/tests/test-rebase-templates.t
@@ -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
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -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,
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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
 
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -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):