hgext3rd/evolve/obshistory.py
changeset 4949 eb9bcef7cc5f
parent 4948 069cfc5301fb
child 4950 60d2065b720b
--- 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