Mercurial > hg-stable
changeset 4352:051fb8c2567c
command line templates: add formatnode filter
This will print a full hash node with --debug and a short one otherwise.
Use it with some default templates and in map-cmdline.default to print
the parents. This should fix issue538.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 16 Apr 2007 13:00:23 -0300 |
parents | 3380eb6d7c32 |
children | 5e857d72d3ac |
files | mercurial/cmdutil.py templates/map-cmdline.default tests/test-command-template tests/test-command-template.out |
diffstat | 4 files changed, 39 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Apr 16 13:00:23 2007 -0300 +++ b/mercurial/cmdutil.py Mon Apr 16 13:00:23 2007 -0300 @@ -325,10 +325,14 @@ def __init__(self, ui, repo, patch, brinfo, mapfile, buffered): changeset_printer.__init__(self, ui, repo, patch, brinfo, buffered) - self.t = templater.templater(mapfile, templater.common_filters, - cache={'parent': '{rev}:{node|short} ', - 'manifest': '{rev}:{node|short}', - 'filecopy': '{name} ({source})'}) + filters = templater.common_filters.copy() + filters['formatnode'] = (ui.debugflag and (lambda x: x) + or (lambda x: x[:12])) + self.t = templater.templater(mapfile, filters, + cache={ + 'parent': '{rev}:{node|formatnode} ', + 'manifest': '{rev}:{node|formatnode}', + 'filecopy': '{name} ({source})'}) def use_template(self, t): '''set template string to use'''
--- a/templates/map-cmdline.default Mon Apr 16 13:00:23 2007 -0300 +++ b/templates/map-cmdline.default Mon Apr 16 13:00:23 2007 -0300 @@ -1,4 +1,4 @@ -changeset = 'changeset: {rev}:{node|short}\n{branches}{tags}{short_parents}user: {author}\ndate: {date|date}\nsummary: {desc|firstline}\n\n' +changeset = 'changeset: {rev}:{node|short}\n{branches}{tags}{parents}user: {author}\ndate: {date|date}\nsummary: {desc|firstline}\n\n' changeset_quiet = '{rev}:{node|short}\n' changeset_verbose = 'changeset: {rev}:{node|short}\n{branches}{tags}{parents}{manifest}user: {author}\ndate: {date|date}\n{files}{file_adds}{file_dels}{file_copies}description:\n{desc|strip}\n\n\n' changeset_debug = 'changeset: {rev}:{node}\n{branches}{tags}{parents}{manifest}user: {author}\ndate: {date|date}\n{files}{file_adds}{file_dels}{file_copies}{extras}description:\n{desc|strip}\n\n\n' @@ -14,8 +14,7 @@ start_file_copies = 'copies: ' file_copy = ' {name} ({source})' end_file_copies = '\n' -short_parent = 'parent: {rev}:{node|short}\n' -parent = 'parent: {rev}:{node}\n' +parent = 'parent: {rev}:{node|formatnode}\n' manifest = 'manifest: {rev}:{node}\n' branch = 'branch: {branch}\n' tag = 'tag: {tag}\n'
--- a/tests/test-command-template Mon Apr 16 13:00:23 2007 -0300 +++ b/tests/test-command-template Mon Apr 16 13:00:23 2007 -0300 @@ -96,6 +96,16 @@ hg log --template '{desc|firstline}\n' hg log --template '{node|short}\n' +echo '# formatnode filter works' +echo '# quiet' +hg -q log -r 0 --template '#node|formatnode#\n' +echo '# normal' +hg log -r 0 --template '#node|formatnode#\n' +echo '# verbose' +hg -v log -r 0 --template '#node|formatnode#\n' +echo '# debug' +hg --debug log -r 0 --template '#node|formatnode#\n' + echo '# error on syntax' echo 'x = "f' >> t hg log
--- a/tests/test-command-template.out Mon Apr 16 13:00:23 2007 -0300 +++ b/tests/test-command-template.out Mon Apr 16 13:00:23 2007 -0300 @@ -230,11 +230,11 @@ manifest--verbose: manifest--verbose: manifest--verbose: -manifest--debug: 4:90ae8dda64e1 -manifest--debug: 3:cb5a1327723b -manifest--debug: 2:6e0e82995c35 -manifest--debug: 1:4e8d705b1e53 -manifest--debug: 0:a0c8bcbbb45c +manifest--debug: 4:90ae8dda64e1a876c792bccb9af66284f6018363 +manifest--debug: 3:cb5a1327723bada42f117e4c55a303246eaf9ccc +manifest--debug: 2:6e0e82995c35d0d57a52aca8da4e56139e06b4b1 +manifest--debug: 1:4e8d705b1e53e3f9375e0e60dc7b525d8211fe55 +manifest--debug: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0 node: 32a18f097fcccf76ef282f62f8a85b3adf8d13c4 node: 10e46f2dcbf4823578cf180f33ecf0b957964c47 node: 97054abb4ab824450e9164180baf491ae0078465 @@ -260,11 +260,11 @@ parents--verbose: parents--verbose: parents--verbose: -parents--debug: 3:10e46f2dcbf4 -1:000000000000 -parents--debug: 2:97054abb4ab8 -1:000000000000 -parents--debug: 1:b608e9d1a3f0 -1:000000000000 -parents--debug: 0:1e4e1b8f71e0 -1:000000000000 -parents--debug: -1:000000000000 -1:000000000000 +parents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47 -1:0000000000000000000000000000000000000000 +parents--debug: 2:97054abb4ab824450e9164180baf491ae0078465 -1:0000000000000000000000000000000000000000 +parents--debug: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965 -1:0000000000000000000000000000000000000000 +parents--debug: 0:1e4e1b8f71e05681d422154f5421e385fec3454f -1:0000000000000000000000000000000000000000 +parents--debug: -1:0000000000000000000000000000000000000000 -1:0000000000000000000000000000000000000000 rev: 4 rev: 3 rev: 2 @@ -336,6 +336,15 @@ 97054abb4ab8 b608e9d1a3f0 1e4e1b8f71e0 +# formatnode filter works +# quiet +1e4e1b8f71e0 +# normal +1e4e1b8f71e0 +# verbose +1e4e1b8f71e0 +# debug +1e4e1b8f71e05681d422154f5421e385fec3454f # error on syntax abort: t:3: unmatched quotes # done