changeset 4949:eb9bcef7cc5f

obslog: redefine default output as a template, unless -f was given This was easier than I expected to do without affecting any test output at all. `hg obslog -f` is pretty broken with templating. For example, it inserts a single "date" field, but it provides two values for it if the dates are different. That results in a traceback when running e.g. `hg obslog -f -Tfoo` with non-local obsmarkers with different dates. We need to figure out what we want to put in the template for the filtered case. I've just left it out for now.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Nov 2019 23:17:34 -0800
parents 069cfc5301fb
children 60d2065b720b
files hgext3rd/evolve/obshistory.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obshistory.py	Thu Nov 07 23:15:29 2019 -0800
+++ b/hgext3rd/evolve/obshistory.py	Thu Nov 07 23:17:34 2019 -0800
@@ -86,6 +86,13 @@
         revs = [b'.']
     revs = scmutil.revrange(repo, revs)
 
+    # Use the default template unless the user provided one, but not if
+    # -f was given, because that doesn't work with templates yet. Note
+    # that --no-graph doesn't support -f (it ignores it), so we also
+    # don't use templating with --no-graph.
+    if not opts['template'] and not (opts['filternonlocal'] and opts['graph']):
+        opts['template'] = DEFAULT_TEMPLATE
+
     if opts['graph']:
         return _debugobshistorygraph(ui, repo, revs, opts)
 
@@ -136,6 +143,33 @@
 
     return values
 
+TEMPLATE_MISSING_NODE = b"""{label("evolve.node evolve.missing_change_ctx", node)}"""
+TEMPLATE_PRESENT_NODE = b"""{label("evolve.node", node)} {label("evolve.rev", "({rev})")} {label("evolve.short_description", desc|firstline)}"""
+TEMPLATE_FIRST_LINE = b"""{if(rev, "%(presentnode)s", "%(missingnode)s")}""" % {
+    b"presentnode": TEMPLATE_PRESENT_NODE,
+    b"missingnode": TEMPLATE_MISSING_NODE
+}
+TEMPLATE_VERB = b"""{label("evolve.verb", verb)}"""
+TEMPLATE_SUCCNODES = b"""{label("evolve.node", join(succnodes % "{succnode}", ", "))}"""
+TEMPLATE_REWRITE = b"""{if(succnodes, "%(verb)s{if(effects, "({join(effects, ", ")})")} as %(succnodes)s", "pruned")}""" % {
+    b"verb": TEMPLATE_VERB,
+    b"succnodes": TEMPLATE_SUCCNODES
+}
+TEMPLATE_OPERATION = b"""{if(operation, "using {label("evolve.operation", operation)}")}"""
+TEMPLATE_USER = b"""by {label("evolve.user", user)}"""
+TEMPLATE_DATE = b"""{label("evolve.date", "({date(date, "%a %b %d %H:%M:%S %Y %1%2")})")}"""
+TEMPLATE_NOTE = b"""{if(note, "\n    note: {label("evolve.note", note)}")}"""
+DEFAULT_TEMPLATE = (b"""%(firstline)s
+{markers %% "  {separate(" ", "%(rewrite)s", "%(operation)s", "%(user)s", "%(date)s")}%(note)s{descdiff}{if(patch, "{patch}")}{if(nopatchreason, "\n    (No patch available, {nopatchreason})")}\n"}
+""") % {
+    b"firstline": TEMPLATE_FIRST_LINE,
+    b"rewrite": TEMPLATE_REWRITE,
+    b"operation": TEMPLATE_OPERATION,
+    b"user": TEMPLATE_USER,
+    b"date": TEMPLATE_DATE,
+    b"note": TEMPLATE_NOTE
+}
+
 class obsmarker_printer(compat.changesetprinter):
     """show (available) information about a node