Patchwork [2,of,2] templatekw: copy {author} to {user} and document {author} as an alias

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 7, 2018, 2:51 p.m.
Message ID <e9622d7f8ced52a5a3c9.1533653507@mimosa>
Download mbox | patch
Permalink /patch/33406/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 7, 2018, 2:51 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1532438001 -32400
#      Tue Jul 24 22:13:21 2018 +0900
# Node ID e9622d7f8ced52a5a3c9a1c6bf40b2a59b44ae69
# Parent  1406a61ddf364b6a069d56cb6db9ddfed757743f
templatekw: copy {author} to {user} and document {author} as an alias

In other places including "log -Tjson" and revset, "user" is the canonical
name. Let's standardize it.

This is a part of the name unification of the Generic Templating Plan.
https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
Augie Fackler - Aug. 7, 2018, 3:26 p.m.
> On Aug 7, 2018, at 10:51, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1532438001 -32400
> #      Tue Jul 24 22:13:21 2018 +0900
> # Node ID e9622d7f8ced52a5a3c9a1c6bf40b2a59b44ae69
> # Parent  1406a61ddf364b6a069d56cb6db9ddfed757743f
> templatekw: copy {author} to {user} and document {author} as an alias

queued these, thanks

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -168,9 +168,8 @@  templatekeyword = registrar.templatekeyw
 
 @templatekeyword('author', requires={'ctx'})
 def showauthor(context, mapping):
-    """String. The unmodified author of the changeset."""
-    ctx = context.resource(mapping, 'ctx')
-    return ctx.user()
+    """Alias for ``{user}``"""
+    return showuser(context, mapping)
 
 @templatekeyword('bisect', requires={'repo', 'ctx'})
 def showbisect(context, mapping):
@@ -757,6 +756,12 @@  def showtermwidth(context, mapping):
     ui = context.resource(mapping, 'ui')
     return ui.termwidth()
 
+@templatekeyword('user', requires={'ctx'})
+def showuser(context, mapping):
+    """String. The unmodified author of the changeset."""
+    ctx = context.resource(mapping, 'ctx')
+    return ctx.user()
+
 @templatekeyword('instabilities', requires={'ctx'})
 def showinstabilities(context, mapping):
     """List of strings. Evolution instabilities affecting the changeset.
diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t
--- a/tests/test-template-keywords.t
+++ b/tests/test-template-keywords.t
@@ -91,7 +91,7 @@  Keys work:
   $ for key in author branch branches date desc file_adds file_dels file_mods \
   >         file_copies file_copies_switch files \
   >         manifest node parents rev tags diffstat extras \
-  >         p1rev p2rev p1node p2node; do
+  >         p1rev p2rev p1node p2node user; do
   >     for mode in '' --verbose --debug; do
   >         hg log $mode --template "$key$mode: {$key}\n"
   >     done
@@ -702,6 +702,33 @@  Keys work:
   p2node--debug: 0000000000000000000000000000000000000000
   p2node--debug: 0000000000000000000000000000000000000000
   p2node--debug: 0000000000000000000000000000000000000000
+  user: test
+  user: User Name <user@hostname>
+  user: person
+  user: person
+  user: person
+  user: person
+  user: other@place
+  user: A. N. Other <other@place>
+  user: User Name <user@hostname>
+  user--verbose: test
+  user--verbose: User Name <user@hostname>
+  user--verbose: person
+  user--verbose: person
+  user--verbose: person
+  user--verbose: person
+  user--verbose: other@place
+  user--verbose: A. N. Other <other@place>
+  user--verbose: User Name <user@hostname>
+  user--debug: test
+  user--debug: User Name <user@hostname>
+  user--debug: person
+  user--debug: person
+  user--debug: person
+  user--debug: person
+  user--debug: other@place
+  user--debug: A. N. Other <other@place>
+  user--debug: User Name <user@hostname>
 
 Add a dummy commit to make up for the instability of the above: