[PATCH] annotate: added the --template and --style parameters
Jesús Espino
jespinog at gmail.com
Sun Feb 19 22:25:33 UTC 2012
# HG changeset patch
# User Jesus Espino Garcia <jesus.espino at kaleidos.net>
# Date 1329690284 -3600
# Node ID b6c95e3ab904d57077f3cf1568c2fe518c07c9f1
# Parent 41fc1e078d6822502277ac80325ec3db99707a6f
annotate: added the --template and --style parameters
diff -r 41fc1e078d68 -r b6c95e3ab904 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Fri Feb 17 13:53:41 2012 -0600
+++ b/mercurial/cmdutil.py Sun Feb 19 23:24:44 2012 +0100
@@ -863,6 +863,38 @@
except SyntaxError, inst:
raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
+class annotate_templater(object):
+ '''format annotate information.'''
+
+ def __init__(self, ui, repo, mapfile):
+ self.ui = ui
+ formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
+ defaulttempl = {
+ 'annotate': '{rev}',
+ }
+ self.t = templater.templater(mapfile, {'formatnode': formatnode},
+ cache=defaulttempl)
+ self.cache = {}
+
+ def use_template(self, t):
+ '''set template string to use'''
+ self.t.cache['annotate'] = t
+
+ def stringify(self, x):
+ '''generate a string result'''
+
+ data = {
+ 'user': x.user(),
+ 'rev': x.rev(),
+ 'node': x.hex(),
+ 'date': x.date(),
+ 'file': x.path(),
+ 'desc': x.description(),
+ 'branch': x.branch(),
+ 'extra': x.extra(),
+ }
+ return ''.join(self.t('annotate', **data))
+
def show_changeset(ui, repo, opts, buffered=False):
"""show one changeset using template or regular display.
diff -r 41fc1e078d68 -r b6c95e3ab904 mercurial/commands.py
--- a/mercurial/commands.py Fri Feb 17 13:53:41 2012 -0600
+++ b/mercurial/commands.py Sun Feb 19 23:24:44 2012 +0100
@@ -219,7 +219,7 @@
('n', 'number', None, _('list the revision number (default)')),
('c', 'changeset', None, _('list the changeset')),
('l', 'line-number', None, _('show line number at the first appearance'))
- ] + diffwsopts + walkopts,
+ ] + diffwsopts + walkopts + templateopts,
_('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'))
def annotate(ui, repo, *pats, **opts):
"""show changeset information by line for each file
@@ -250,16 +250,32 @@
hexfn = ui.debugflag and hex or short
+ if opts.get('style') or opts.get('template'):
+ import templater
+ if not opts.get('style'):
+ mapname = templater.templatepath("map-cmdline.default")
+ else:
+ mapname = (templater.templatepath('map-cmdline.'+opts.get('style'))
+ or templater.templatepath(opts.get('style')))
+
+ t = cmdutil.annotate_templater(ui, repo, mapname)
+
+ if opts.get('template'):
+ t.use_template(opts.get('template'))
+ opts['use_template'] = True
+
opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),
('number', ' ', lambda x: str(x[0].rev())),
('changeset', ' ', lambda x: hexfn(x[0].node())),
('date', ' ', getdate),
('file', ' ', lambda x: x[0].path()),
+ ('use_template', ':', lambda x: t.stringify(x[0])),
('line_number', ':', lambda x: str(x[1])),
]
if (not opts.get('user') and not opts.get('changeset')
- and not opts.get('date') and not opts.get('file')):
+ and not opts.get('date') and not opts.get('file')
+ and not opts.get('use_template')):
opts['number'] = True
linenumber = opts.get('line_number') is not None
diff -r 41fc1e078d68 -r b6c95e3ab904 mercurial/templates/map-cmdline.default
--- a/mercurial/templates/map-cmdline.default Fri Feb 17 13:53:41 2012 -0600
+++ b/mercurial/templates/map-cmdline.default Sun Feb 19 23:24:44 2012 +0100
@@ -23,3 +23,4 @@
tag = 'tag: {tag}\n'
bookmark = 'bookmark: {bookmark}\n'
extra = 'extra: {key}={value|stringescape}\n'
+annotate = '{rev}'
diff -r 41fc1e078d68 -r b6c95e3ab904 tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t Fri Feb 17 13:53:41 2012 -0600
+++ b/tests/test-debugcomplete.t Sun Feb 19 23:24:44 2012 +0100
@@ -190,7 +190,7 @@
Show all commands + options
$ hg debugcommands
add: include, exclude, subrepos, dry-run
- annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
+ annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude, style, template
clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
commit: addremove, close-branch, include, exclude, message, logfile, date, user, subrepos
diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
More information about the Mercurial-devel
mailing list