Patchwork [8,of,8] annotate: automatically populate fields referenced from template

login
register
mail settings
Submitter Yuya Nishihara
Date June 14, 2018, 3:40 p.m.
Message ID <a10173987e2dfab78934.1528990833@mimosa>
Download mbox | patch
Permalink /patch/32138/
State Accepted
Headers show

Comments

Yuya Nishihara - June 14, 2018, 3:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1525316676 -32400
#      Thu May 03 12:04:36 2018 +0900
# Node ID a10173987e2dfab78934c7b4c6ed621eead67b05
# Parent  ef1de4fc1e7c02e4368123ff7abacbd157c42aa7
annotate: automatically populate fields referenced from template

If '{line_number}' is in the template, we'll probably need it. No
--line-number option should be required in such cases.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -359,11 +359,12 @@  def annotate(ui, repo, *pats, **opts):
     else:
         def makefunc(get, fmt):
             return get
+    datahint = rootfm.datahint()
     funcmap = [(makefunc(get, fmt), sep) for fn, sep, get, fmt in opmap
-               if opts.get(opnamemap.get(fn, fn))]
+               if opts.get(opnamemap.get(fn, fn)) or fn in datahint]
     funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
     fields = ' '.join(fn for fn, sep, get, fmt in opmap
-                      if opts.get(opnamemap.get(fn, fn)))
+                      if opts.get(opnamemap.get(fn, fn)) or fn in datahint)
 
     def bad(x, y):
         raise error.Abort("%s: %s" % (x, y))
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -76,6 +76,11 @@  log-like templating
   $ hg annotate -T'{lines % "{rev} {node|shortest}: {line}"}' a
   0 8435: a
 
+'{line_number}' field should be populated as necessary
+
+  $ hg annotate -T'{lines % "{rev}:{line_number}: {line}"}' a
+  0:1: a
+
   $ cat <<EOF >>a
   > a
   > a