Patchwork [1,of,3] commands: unify template output to use name (BC)

login
register
mail settings
Submitter timeless@mozdev.org
Date April 13, 2016, 5:14 p.m.
Message ID <57f09cb9c2e69b0e8ef8.1460567674@waste.org>
Download mbox | patch
Permalink /patch/14587/
State Deferred
Headers show

Comments

timeless@mozdev.org - April 13, 2016, 5:14 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1456505030 0
#      Fri Feb 26 16:43:50 2016 +0000
# Node ID 57f09cb9c2e69b0e8ef89cd21758722ba7e07ff6
# Parent  02be5fc18c0c70c087a9d1ab5ffe5afce926f227
commands: unify template output to use name (BC)

Before this, hg bookmarks -T... and hg tags -T used
bookmark/tag respectively for the name of the repesective
bookmark/tag, but it is really a name, and there is no reason to
repeat "bookmark" or "tag" in a command named "bookmarks" or "tags",
obviously the things you will get will be bookmarks or tags.

{tag} and {bookmark} remain available for backwards compatibility.
Yuya Nishihara - April 15, 2016, 4:14 p.m.
On Wed, 13 Apr 2016 12:14:34 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1456505030 0
> #      Fri Feb 26 16:43:50 2016 +0000
> # Node ID 57f09cb9c2e69b0e8ef89cd21758722ba7e07ff6
> # Parent  02be5fc18c0c70c087a9d1ab5ffe5afce926f227
> commands: unify template output to use name (BC)
> 
> Before this, hg bookmarks -T... and hg tags -T used
> bookmark/tag respectively for the name of the repesective
> bookmark/tag, but it is really a name, and there is no reason to
> repeat "bookmark" or "tag" in a command named "bookmarks" or "tags",
> obviously the things you will get will be bookmarks or tags.
> 
> {tag} and {bookmark} remain available for backwards compatibility.

This looks okay to me, though I don't know how great it will be to provide
the "name" keyword.

I'm 0 for this. Needs more eyes.
Matt Mackall - April 16, 2016, 9:25 p.m.
On Sat, 2016-04-16 at 01:14 +0900, Yuya Nishihara wrote:
> On Wed, 13 Apr 2016 12:14:34 -0500, timeless wrote:
> > 
> > # HG changeset patch
> > # User timeless <timeless@mozdev.org>
> > # Date 1456505030 0
> > #      Fri Feb 26 16:43:50 2016 +0000
> > # Node ID 57f09cb9c2e69b0e8ef89cd21758722ba7e07ff6
> > # Parent  02be5fc18c0c70c087a9d1ab5ffe5afce926f227
> > commands: unify template output to use name (BC)
> > 
> > Before this, hg bookmarks -T... and hg tags -T used
> > bookmark/tag respectively for the name of the repesective
> > bookmark/tag, but it is really a name, and there is no reason to
> > repeat "bookmark" or "tag" in a command named "bookmarks" or "tags",
> > obviously the things you will get will be bookmarks or tags.
> > 
> > {tag} and {bookmark} remain available for backwards compatibility.
> This looks okay to me, though I don't know how great it will be to provide
> the "name" keyword.

Yeah, I dunno. Currently, our list-like elements (grep for showlist in
templatekw.py) work like:

{files % "file: {file}\n"}

In the spirit of allowing the user to discover the available template structure
via -Tjson, we should probably match the existing element names.

Going to drop this until 3.9 opens up.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1194,7 +1194,8 @@ 
             fm.startitem()
             if not ui.quiet:
                 fm.plain(' %s ' % prefix, label=label)
-            fm.write('bookmark', '%s', bmark, label=label)
+            fm.write('name', '%s', bmark, label=label)
+            fm.data(bookmark=bmark)
             pad = " " * (25 - encoding.colwidth(bmark))
             fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s',
                          repo.changelog.rev(n), hexfn(n), label=label)
@@ -7022,7 +7023,8 @@ 
             tagtype = 'local'
 
         fm.startitem()
-        fm.write('tag', '%s', t, label=label)
+        fm.write('name', '%s', t, label=label)
+        fm.data(tag=t)
         fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
         fm.condwrite(not ui.quiet, 'rev node', fmt,
                      repo.changelog.rev(n), hn, label=label)
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -68,18 +68,21 @@ 
    {
     "active": false,
     "bookmark": "X",
+    "name": "X",
     "node": "f7b1eb17ad24730a1651fccd46c43826d1bbc2ac",
     "rev": 0
    },
    {
     "active": true,
     "bookmark": "X2",
+    "name": "X2",
     "node": "925d80f479bb026b0fb3deb27503780b13f74123",
     "rev": 1
    },
    {
     "active": false,
     "bookmark": "Y",
+    "name": "Y",
     "node": "0000000000000000000000000000000000000000",
     "rev": -1
    }
diff --git a/tests/test-encoding.t b/tests/test-encoding.t
--- a/tests/test-encoding.t
+++ b/tests/test-encoding.t
@@ -184,12 +184,14 @@ 
   $ hg tags -Tjson
   [
    {
+    "name": "tip",
     "node": "a52c0692f24ad921c0a31e1736e7635a8b23b670",
     "rev": 5,
     "tag": "tip",
     "type": ""
    },
    {
+    "name": "\xc3\xa9", (esc)
     "node": "ca661e7520dec3f5438a63590c350bebadb04989",
     "rev": 3,
     "tag": "\xc3\xa9", (esc)