changeset 21078:50107a4b32e7

cat: explicitly document the supported formatter rules The previous documentation pointed to the export command, but even if the user recognized that instead of only reading the cat specific list of rules, not all of the export rules applied anyway (specifically %N, %n and %m). The new items are a copy/paste from export's list. These rules have existed since at least version 0.5. Note that %m gets substituted with 'None' because the commit message isn't passed to cmdutil.makefilename(). %R and %r are currently effectively the same, since no revwidth is passed, however they both work. There aren't any existing tests for these rules, so they are added to prevent future regression.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 15 Apr 2014 23:29:19 -0400
parents 78b15ad2f968
children b02ab6486a78
files mercurial/commands.py tests/test-cat.t
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Apr 16 01:10:08 2014 +0200
+++ b/mercurial/commands.py	Tue Apr 15 23:29:19 2014 -0400
@@ -1162,12 +1162,17 @@
     no revision is given, the parent of the working directory is used.
 
     Output may be to a file, in which case the name of the file is
-    given using a format string. The formatting rules are the same as
-    for the export command, with the following additions:
-
+    given using a format string. The formatting rules as follows:
+
+    :``%%``: literal "%" character
     :``%s``: basename of file being printed
     :``%d``: dirname of file being printed, or '.' if in repository root
     :``%p``: root-relative path name of file being printed
+    :``%H``: changeset hash (40 hexadecimal digits)
+    :``%R``: changeset revision number
+    :``%h``: short-form changeset hash (12 hexadecimal digits)
+    :``%r``: zero-padded changeset revision number
+    :``%b``: basename of the exporting repository
 
     Returns 0 on success.
     """
--- a/tests/test-cat.t	Wed Apr 16 01:10:08 2014 +0200
+++ b/tests/test-cat.t	Tue Apr 15 23:29:19 2014 -0400
@@ -32,3 +32,22 @@
   1
   3
 
+  $ mkdir tmp
+  $ hg cat --output tmp/HH_%H c
+  $ hg cat --output tmp/RR_%R c
+  $ hg cat --output tmp/h_%h c
+  $ hg cat --output tmp/r_%r c
+  $ hg cat --output tmp/%s_s c
+  $ hg cat --output tmp/%d%%_d c
+  $ hg cat --output tmp/%p_p c
+  $ hg log -r . --template "{rev}: {node|short}\n"
+  2: 45116003780e
+  $ find tmp -type f | sort
+  tmp/.%_d
+  tmp/HH_45116003780e3678b333fb2c99fa7d559c8457e9
+  tmp/RR_2
+  tmp/c_p
+  tmp/c_s
+  tmp/h_45116003780e
+  tmp/r_2
+