Patchwork [4,of,4,V2] annotate: add support for template keywords and functions depending on ctx

login
register
mail settings
Submitter Yuya Nishihara
Date March 16, 2018, 4:03 p.m.
Message ID <654506d13eb9df1cd358.1521216201@mimosa>
Download mbox | patch
Permalink /patch/29569/
State New
Headers show

Comments

Yuya Nishihara - March 16, 2018, 4:03 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520771788 -32400
#      Sun Mar 11 21:36:28 2018 +0900
# Node ID 654506d13eb9df1cd358266a3fc180dabcd1db52
# Parent  f810d481d55c0573912058c68c615bfa30e20805
annotate: add support for template keywords and functions depending on ctx

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -405,14 +405,15 @@  def annotate(ui, repo, *pats, **opts):
                 formats.append(['%s' for x in l])
             pieces.append(l)
 
-        for f, p, l in zip(zip(*formats), zip(*pieces), lines):
+        for f, p, (n, l) in zip(zip(*formats), zip(*pieces), lines):
             fm.startitem()
+            fm.context(fctx=n.fctx)
             fm.write(fields, "".join(f), *p)
-            if l[0].skip:
+            if n.skip:
                 fmt = "* %s"
             else:
                 fmt = ": %s"
-            fm.write('line', fmt, l[1])
+            fm.write('line', fmt, l)
 
         if not lines[-1][1].endswith('\n'):
             fm.plain('\n')
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -71,6 +71,11 @@  annotate (JSON)
    }
   ]
 
+log-like templating
+
+  $ hg annotate -T'{lines % "{rev} {node|shortest}: {line}"}' a
+  0 8435: a
+
   $ cat <<EOF >>a
   > a
   > a