mercurial/cmdutil.py
changeset 45793 96fcc37a9c80
parent 45720 508dfd1c18df
child 45794 f90a5c211251
--- 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