Patchwork [2,of,7] annotate: rename {lines}/{line} to {texts}/{text} respectively (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 30, 2018, 1:43 p.m.
Message ID <4ee07da344653b4bcfea.1538315026@mimosa>
Download mbox | patch
Permalink /patch/35218/
State Superseded
Headers show

Comments

Yuya Nishihara - Sept. 30, 2018, 1:43 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1538288821 -32400
#      Sun Sep 30 15:27:01 2018 +0900
# Node ID 4ee07da344653b4bcfea8214c20e713cfd307d86
# Parent  66d94b8a5526475ae523e1cca3bfd8c1cf3ec9ca
annotate: rename {lines}/{line} to {texts}/{text} respectively (BC)

Perhaps these were the most unloved names. While the data structure is
different from the {texts} in "hg grep", they are more or less a list of
text chunks with some metadata attached. Let's call both of them as {texts}
since I couldn't come up with a better name.

https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
Anton Shestakov - Oct. 1, 2018, 7:38 a.m.
On Sun, 30 Sep 2018 22:43:46 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1538288821 -32400
> #      Sun Sep 30 15:27:01 2018 +0900
> # Node ID 4ee07da344653b4bcfea8214c20e713cfd307d86
> # Parent  66d94b8a5526475ae523e1cca3bfd8c1cf3ec9ca
> annotate: rename {lines}/{line} to {texts}/{text} respectively (BC)
> 
> Perhaps these were the most unloved names. While the data structure is
> different from the {texts} in "hg grep", they are more or less a list of
> text chunks with some metadata attached. Let's call both of them as {texts}
> since I couldn't come up with a better name.
> 
> https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -390,7 +390,7 @@ def annotate(ui, repo, *pats, **opts):
>                           % ((pats and m.rel(abs)) or abs))
>              continue
>  
> -        fm = rootfm.nested('lines', tmpl='{rev}: {line}')
> +        fm = rootfm.nested('texts', tmpl='{rev}: {text}')

I personally would expect the iterable to be named "lines", e.g.:

    rootfm.nested('lines', tmpl='{rev}: {text}')

It makes sense in my mind because these are not just randomly cut text
chunks, they are individual lines, no more no less. We're iterating the
output of annotate (and grep too) line by line, not text (e.g. a
paragraph or more) by text.
Yuya Nishihara - Oct. 1, 2018, 10:55 a.m.
On Mon, 1 Oct 2018 15:38:36 +0800, Anton Shestakov wrote:
> On Sun, 30 Sep 2018 22:43:46 +0900
> Yuya Nishihara <yuya@tcha.org> wrote:
> 
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1538288821 -32400
> > #      Sun Sep 30 15:27:01 2018 +0900
> > # Node ID 4ee07da344653b4bcfea8214c20e713cfd307d86
> > # Parent  66d94b8a5526475ae523e1cca3bfd8c1cf3ec9ca
> > annotate: rename {lines}/{line} to {texts}/{text} respectively (BC)
> > 
> > Perhaps these were the most unloved names. While the data structure is
> > different from the {texts} in "hg grep", they are more or less a list of
> > text chunks with some metadata attached. Let's call both of them as {texts}
> > since I couldn't come up with a better name.
> > 
> > https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
> > 
> > diff --git a/mercurial/commands.py b/mercurial/commands.py
> > --- a/mercurial/commands.py
> > +++ b/mercurial/commands.py
> > @@ -390,7 +390,7 @@ def annotate(ui, repo, *pats, **opts):
> >                           % ((pats and m.rel(abs)) or abs))
> >              continue
> >  
> > -        fm = rootfm.nested('lines', tmpl='{rev}: {line}')
> > +        fm = rootfm.nested('texts', tmpl='{rev}: {text}')
> 
> I personally would expect the iterable to be named "lines", e.g.:
> 
>     rootfm.nested('lines', tmpl='{rev}: {text}')
> 
> It makes sense in my mind because these are not just randomly cut text
> chunks, they are individual lines, no more no less. We're iterating the
> output of annotate (and grep too) line by line, not text (e.g. a
> paragraph or more) by text.

Okay. Let's not rename the lines/line pair then. I don't have any preference
over lines vs texts, but I don't like the inconsistency of lines[n] -> text.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -390,7 +390,7 @@  def annotate(ui, repo, *pats, **opts):
                          % ((pats and m.rel(abs)) or abs))
             continue
 
-        fm = rootfm.nested('lines', tmpl='{rev}: {line}')
+        fm = rootfm.nested('texts', tmpl='{rev}: {text}')
         lines = fctx.annotate(follow=follow, skiprevs=skiprevs,
                               diffopts=diffopts)
         if not lines:
@@ -417,7 +417,7 @@  def annotate(ui, repo, *pats, **opts):
                 fmt = "* %s"
             else:
                 fmt = ": %s"
-            fm.write('line', fmt, n.text)
+            fm.write('text', fmt, n.text)
 
         if not lines[-1].text.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
@@ -56,30 +56,30 @@  annotate (JSON)
   $ hg annotate -Tjson a
   [
    {
-    "lines": [{"line": "a\n", "rev": 0}],
-    "path": "a"
+    "path": "a",
+    "texts": [{"rev": 0, "text": "a\n"}]
    }
   ]
 
   $ hg annotate -Tjson -cdfnul a
   [
    {
-    "lines": [{"date": [1.0, 0], "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "user": "nobody"}],
-    "path": "a"
+    "path": "a",
+    "texts": [{"date": [1.0, 0], "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "text": "a\n", "user": "nobody"}]
    }
   ]
 
 log-like templating
 
-  $ hg annotate -T'{lines % "{rev} {node|shortest}: {line}"}' a
+  $ hg annotate -T'{texts % "{rev} {node|shortest}: {text}"}' a
   0 8435: a
 
 '{line_number}' field should be populated as necessary
 
-  $ hg annotate -T'{lines % "{rev}:{line_number}: {line}"}' a
+  $ hg annotate -T'{texts % "{rev}:{line_number}: {text}"}' a
   0:1: a
   $ hg annotate -Ta a \
-  > --config templates.a='"{lines % "{rev}:{line_number}: {line}"}"'
+  > --config templates.a='"{texts % "{rev}:{line_number}: {text}"}"'
   0:1: a
 
   $ cat <<EOF >>a
@@ -96,28 +96,28 @@  log-like templating
   > EOF
   $ hg ci -mb2 -d '2 0'
 
-default output of '{lines}' should be readable
+default output of '{texts}' should be readable
 
-  $ hg annotate -T'{lines}' a
+  $ hg annotate -T'{texts}' a
   0: a
   1: a
   1: a
-  $ hg annotate -T'{join(lines, "\n")}' a
+  $ hg annotate -T'{join(texts, "\n")}' a
   0: a
   
   1: a
   
   1: a
 
-several filters can be applied to '{lines}'
+several filters can be applied to '{texts}'
 
-  $ hg annotate -T'{lines|json}\n' a
-  [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}]
-  $ hg annotate -T'{lines|stringify}' a
+  $ hg annotate -T'{texts|json}\n' a
+  [{"rev": 0, "text": "a\n"}, {"rev": 1, "text": "a\n"}, {"rev": 1, "text": "a\n"}]
+  $ hg annotate -T'{texts|stringify}' a
   0: a
   1: a
   1: a
-  $ hg annotate -T'{lines|count}\n' a
+  $ hg annotate -T'{texts|count}\n' a
   3
 
 annotate multiple files (JSON)
@@ -125,18 +125,18 @@  annotate multiple files (JSON)
   $ hg annotate -Tjson a b
   [
    {
-    "lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}],
-    "path": "a"
+    "path": "a",
+    "texts": [{"rev": 0, "text": "a\n"}, {"rev": 1, "text": "a\n"}, {"rev": 1, "text": "a\n"}]
    },
    {
-    "lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}, {"line": "b4\n", "rev": 3}, {"line": "b5\n", "rev": 3}, {"line": "b6\n", "rev": 3}],
-    "path": "b"
+    "path": "b",
+    "texts": [{"rev": 0, "text": "a\n"}, {"rev": 1, "text": "a\n"}, {"rev": 1, "text": "a\n"}, {"rev": 3, "text": "b4\n"}, {"rev": 3, "text": "b5\n"}, {"rev": 3, "text": "b6\n"}]
    }
   ]
 
 annotate multiple files (template)
 
-  $ hg annotate -T'== {path} ==\n{lines % "{rev}: {line}"}' a b
+  $ hg annotate -T'== {path} ==\n{texts % "{rev}: {text}"}' a b
   == a ==
   0: a
   1: a
@@ -564,8 +564,8 @@  annotate modified file
   $ hg annotate -ncr "wdir()" -Tjson foo
   [
    {
-    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647}],
-    "path": "foo"
+    "path": "foo",
+    "texts": [{"node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11, "text": "foo\n"}, {"node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647, "text": "foofoo\n"}]
    }
   ]
 
@@ -868,8 +868,8 @@  Test empty annotate output
     "path": "binary"
    },
    {
-    "lines": [],
-    "path": "empty"
+    "path": "empty",
+    "texts": []
    }
   ]
 
diff --git a/tests/test-fastannotate-hg.t b/tests/test-fastannotate-hg.t
--- a/tests/test-fastannotate-hg.t
+++ b/tests/test-fastannotate-hg.t
@@ -69,16 +69,16 @@  annotate (JSON)
   $ hg annotate -Tjson a
   [
    {
-    "lines": [{"line": "a\n", "rev": 0}],
-    "path": "a"
+    "path": "a",
+    "texts": [{"rev": 0, "text": "a\n"}]
    }
   ]
 
   $ hg annotate -Tjson -cdfnul a
   [
    {
-    "lines": [{"date": [1.0, 0], "line": "a\n", "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "user": "nobody"}],
-    "path": "a"
+    "path": "a",
+    "texts": [{"date": [1.0, 0], "line_number": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "text": "a\n", "user": "nobody"}]
    }
   ]
 
@@ -569,8 +569,8 @@  annotate modified file
   $ hg annotate -ncr "wdir()" -Tjson foo
   [
    {
-    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647}],
-    "path": "foo"
+    "path": "foo",
+    "texts": [{"node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11, "text": "foo\n"}, {"node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647, "text": "foofoo\n"}]
    }
   ]