[PATCH 2 of 3] template: unify template output to use abspath (BC)

timeless timeless at mozdev.org
Tue Mar 8 14:44:27 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1456509834 0
#      Fri Feb 26 18:03:54 2016 +0000
# Node ID ec4546f50c52baae1db569008c33de7ac06949e3
# Parent  94616d85ab4517fe06424dc1760844de0f4a664e
template: unify template output to use abspath (BC)

Before this change, annotate used "file", which was inaccurate,
the field is actually an abspath.

{file_dels}, {file_adds}, {file_copies}, {files} are changed so their % field
is {abspath} instead of {file}.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -428,7 +428,11 @@
              ('file', ' ', lambda x: x[0].path(), str),
              ('line_number', ':', lambda x: x[1], str),
             ]
-    fieldnamemap = {'number': 'rev', 'changeset': 'node'}
+    fieldnamemap = {
+             'changeset': 'node',
+             'file': 'abspath',
+             'number': 'rev',
+            }
 
     if (not opts.get('user') and not opts.get('changeset')
         and not opts.get('date') and not opts.get('file')):
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -288,7 +288,7 @@
     """:file_adds: List of strings. Files added by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
     return showlist('file_add', getfiles(repo, ctx, revcache)[1],
-                    element='file', **args)
+                    element='abspath', **args)
 
 def showfilecopies(**args):
     """:file_copies: List of strings. Files copied in this changeset with
@@ -332,19 +332,19 @@
     """:file_dels: List of strings. Files removed by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
     return showlist('file_del', getfiles(repo, ctx, revcache)[2],
-                    element='file', **args)
+                    element='abspath', **args)
 
 def showfilemods(**args):
     """:file_mods: List of strings. Files modified by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
     return showlist('file_mod', getfiles(repo, ctx, revcache)[0],
-                    element='file', **args)
+                    element='abspath', **args)
 
 def showfiles(**args):
     """:files: List of strings. All files modified, added, or removed by this
     changeset.
     """
-    return showlist('file', args['ctx'].files(), **args)
+    return showlist('file', args['ctx'].files(), element='abspath', **args)
 
 def showgraphnode(repo, ctx, **args):
     """:graphnode: String. The character representing the changeset node in
diff --git a/mercurial/templates/map-cmdline.status b/mercurial/templates/map-cmdline.status
--- a/mercurial/templates/map-cmdline.status
+++ b/mercurial/templates/map-cmdline.status
@@ -11,15 +11,15 @@
                     'files:\n'))}{lfile_mods}{lfile_adds}{lfile_copies_switch}{lfile_dels}'
 
 # Exclude copied files, will display those in lfile_copies_switch
-lfile_adds  = '{file_adds % "{ifcontains(file, file_copies_switch,
+lfile_adds  = '{file_adds % "{ifcontains(abspath, file_copies_switch,
                                          '',
                                          '{lfile_add}')}"}'
-lfile_add = '{label("status.added", "A {file}\n")}'
+lfile_add = '{label("status.added", "A {abspath}\n")}'
 
 lfile_copies_switch = '{file_copies_switch % "{lfile_copy_orig}{lfile_copy_dest}"}'
 lfile_copy_orig = '{label("status.added", "A {name}\n")}'
 lfile_copy_dest = '{label("status.copied", "  {source}\n")}'
 
-lfile_mods = '{file_mods % "{label('status.modified', 'M {file}\n')}"}'
+lfile_mods = '{file_mods % "{label('status.modified', 'M {abspath}\n')}"}'
 
-lfile_dels = '{file_dels % "{label('status.removed', 'R {file}\n')}"}'
+lfile_dels = '{file_dels % "{label('status.removed', 'R {abspath}\n')}"}'
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -64,8 +64,8 @@
   $ hg annotate -Tjson -cdfnul a
   [
    {
+    "abspath": "a",
     "date": [1.0, 0],
-    "file": "a",
     "line": "a\n",
     "line_number": 1,
     "node": "8435f90966e442695d2ded29fdade2bac5ad8065",
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2787,7 +2787,7 @@
 
 Test new-style inline templating:
 
-  $ hg log -R latesttag -r tip --template 'modified files: {file_mods % " {file}\n"}\n'
+  $ hg log -R latesttag -r tip --template 'modified files: {file_mods % " {abspath}\n"}\n'
   modified files:  .hgtags
   
 Test the sub function of templating for expansion:
@@ -2955,7 +2955,7 @@
 stripped before parsing:
 
   $ cat <<'EOF' > escquotetmpl
-  > changeset = "\" \\" \\\" \\\\" {files % \"{file}\"}\n"
+  > changeset = "\" \\" \\\" \\\\" {files % \"{abspath}\"}\n"
   > EOF
   $ cd latesttag
   $ hg log -r 2 --style ../escquotetmpl
@@ -3011,12 +3011,12 @@
 Test leading backslashes:
 
   $ cd latesttag
-  $ hg log -r 2 -T '\{rev} {files % "\{file}"}\n'
-  {rev} {file}
-  $ hg log -r 2 -T '\\{rev} {files % "\\{file}"}\n'
+  $ hg log -r 2 -T '\{rev} {files % "\{abspath}"}\n'
+  {rev} {abspath}
+  $ hg log -r 2 -T '\\{rev} {files % "\\{abspath}"}\n'
   \2 \head1
-  $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"}\n'
-  \{rev} \{file}
+  $ hg log -r 2 -T '\\\{rev} {files % "\\\{abspath}"}\n'
+  \{rev} \{abspath}
   $ cd ..
 
 Test leading backslashes in "if" expression (issue4714):
@@ -3093,7 +3093,7 @@
   $ hg log -R a -r 2 --template '{sub("n", r"\x2d", r"no perso\x6e")}\n'
   \x2do perso\x6e
 
-  $ hg log -R a -r 8 --template '{files % "{file}\n"}'
+  $ hg log -R a -r 8 --template '{files % "{abspath}\n"}'
   fourth
   second
   third
diff --git a/tests/test-convert-filemap.t b/tests/test-convert-filemap.t
--- a/tests/test-convert-filemap.t
+++ b/tests/test-convert-filemap.t
@@ -724,7 +724,7 @@
   converted/a
   converted/b
   x
-  $ hg -R merge-test2 log -G -T '{shortest(node)} {desc}\n{files % "- {file}\n"}\n'
+  $ hg -R merge-test2 log -G -T '{shortest(node)} {desc}\n{files % "- {abspath}\n"}\n'
   o    6eaa merge a & b
   |\   - converted/a
   | |  - toberemoved
@@ -770,7 +770,7 @@
   sorting...
   converting...
   0 3
-  $ hg -R .-hg log -G -T '{shortest(node)} {desc}\n{files % "- {file}\n"}\n'
+  $ hg -R .-hg log -G -T '{shortest(node)} {desc}\n{files % "- {abspath}\n"}\n'
   o    e9ed 3
   |\
   | o  33a0 2
diff --git a/tests/test-mq-qrefresh-replace-log-message.t b/tests/test-mq-qrefresh-replace-log-message.t
--- a/tests/test-mq-qrefresh-replace-log-message.t
+++ b/tests/test-mq-qrefresh-replace-log-message.t
@@ -40,9 +40,9 @@
   $ cat >> .hg/hgrc <<EOF
   > [committemplate]
   > listupfiles = {file_adds %
-  >    "HG: added {file}\n"     }{file_mods %
-  >    "HG: changed {file}\n"   }{file_dels %
-  >    "HG: removed {file}\n"   }{if(files, "",
+  >    "HG: added {abspath}\n"  }{file_mods %
+  >    "HG: changed {abspath}\n"}{file_dels %
+  >    "HG: removed {abspath}\n"}{if(files, "",
   >    "HG: no files changed\n")}
   > 
   > changeset = HG: this is customized commit template


More information about the Mercurial-devel mailing list