##// END OF EJS Templates
annotate: port to generic templater enabled by hidden -T option...
Yuya Nishihara -
r22480:dff63817 default
parent child Browse files
Show More
@@ -247,7 +247,7 b' def addremove(ui, repo, *pats, **opts):'
247 ('n', 'number', None, _('list the revision number (default)')),
247 ('n', 'number', None, _('list the revision number (default)')),
248 ('c', 'changeset', None, _('list the changeset')),
248 ('c', 'changeset', None, _('list the changeset')),
249 ('l', 'line-number', None, _('show line number at the first appearance'))
249 ('l', 'line-number', None, _('show line number at the first appearance'))
250 ] + diffwsopts + walkopts,
250 ] + diffwsopts + walkopts + formatteropts,
251 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
251 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
252 inferrepo=True)
252 inferrepo=True)
253 def annotate(ui, repo, *pats, **opts):
253 def annotate(ui, repo, *pats, **opts):
@@ -274,8 +274,12 b' def annotate(ui, repo, *pats, **opts):'
274 # to mimic the behavior of Mercurial before version 1.5
274 # to mimic the behavior of Mercurial before version 1.5
275 opts['file'] = True
275 opts['file'] = True
276
276
277 fm = ui.formatter('annotate', opts)
277 datefunc = ui.quiet and util.shortdate or util.datestr
278 datefunc = ui.quiet and util.shortdate or util.datestr
278 hexfn = ui.debugflag and hex or short
279 if fm or ui.debugflag:
280 hexfn = hex
281 else:
282 hexfn = short
279
283
280 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser),
284 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser),
281 ('number', ' ', lambda x: x[0].rev(), str),
285 ('number', ' ', lambda x: x[0].rev(), str),
@@ -284,6 +288,7 b' def annotate(ui, repo, *pats, **opts):'
284 ('file', ' ', lambda x: x[0].path(), str),
288 ('file', ' ', lambda x: x[0].path(), str),
285 ('line_number', ':', lambda x: x[1], str),
289 ('line_number', ':', lambda x: x[1], str),
286 ]
290 ]
291 fieldnamemap = {'number': 'rev', 'changeset': 'node'}
287
292
288 if (not opts.get('user') and not opts.get('changeset')
293 if (not opts.get('user') and not opts.get('changeset')
289 and not opts.get('date') and not opts.get('file')):
294 and not opts.get('date') and not opts.get('file')):
@@ -293,11 +298,17 b' def annotate(ui, repo, *pats, **opts):'
293 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
298 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
294 raise util.Abort(_('at least one of -n/-c is required for -l'))
299 raise util.Abort(_('at least one of -n/-c is required for -l'))
295
300
296 def makefunc(get, fmt):
301 if fm:
297 return lambda x: fmt(get(x))
302 def makefunc(get, fmt):
303 return get
304 else:
305 def makefunc(get, fmt):
306 return lambda x: fmt(get(x))
298 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
307 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
299 if opts.get(op)]
308 if opts.get(op)]
300 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
309 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
310 fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap
311 if opts.get(op))
301
312
302 def bad(x, y):
313 def bad(x, y):
303 raise util.Abort("%s: %s" % (x, y))
314 raise util.Abort("%s: %s" % (x, y))
@@ -310,7 +321,7 b' def annotate(ui, repo, *pats, **opts):'
310 for abs in ctx.walk(m):
321 for abs in ctx.walk(m):
311 fctx = ctx[abs]
322 fctx = ctx[abs]
312 if not opts.get('text') and util.binary(fctx.data()):
323 if not opts.get('text') and util.binary(fctx.data()):
313 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
324 fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
314 continue
325 continue
315
326
316 lines = fctx.annotate(follow=follow, linenumber=linenumber,
327 lines = fctx.annotate(follow=follow, linenumber=linenumber,
@@ -321,17 +332,23 b' def annotate(ui, repo, *pats, **opts):'
321 for f, sep in funcmap:
332 for f, sep in funcmap:
322 l = [f(n) for n, dummy in lines]
333 l = [f(n) for n, dummy in lines]
323 if l:
334 if l:
324 sizes = [encoding.colwidth(x) for x in l]
335 if fm:
325 ml = max(sizes)
336 formats.append(['%s' for x in l])
326 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
337 else:
338 sizes = [encoding.colwidth(x) for x in l]
339 ml = max(sizes)
340 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
327 pieces.append(l)
341 pieces.append(l)
328
342
329 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
343 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
330 ui.write("".join(f) % p)
344 fm.startitem()
331 ui.write(": %s" % l[1])
345 fm.write(fields, "".join(f), *p)
346 fm.write('line', ": %s", l[1])
332
347
333 if lines and not lines[-1][1].endswith('\n'):
348 if lines and not lines[-1][1].endswith('\n'):
334 ui.write('\n')
349 fm.plain('\n')
350
351 fm.end()
335
352
336 @command('archive',
353 @command('archive',
337 [('', 'no-decode', None, _('do not pass files through decoders')),
354 [('', 'no-decode', None, _('do not pass files through decoders')),
@@ -51,6 +51,29 b' annotate -cdnul'
51 $ hg annotate -cdnul a
51 $ hg annotate -cdnul a
52 nobody 0 8435f90966e4 Thu Jan 01 00:00:01 1970 +0000:1: a
52 nobody 0 8435f90966e4 Thu Jan 01 00:00:01 1970 +0000:1: a
53
53
54 annotate (JSON)
55
56 $ hg annotate -Tjson a
57 [
58 {
59 "line": "a\n",
60 "rev": 0
61 }
62 ]
63
64 $ hg annotate -Tjson -cdfnul a
65 [
66 {
67 "date": [1.0, 0],
68 "file": "a",
69 "line": "a\n",
70 "line_number": 1,
71 "node": "8435f90966e442695d2ded29fdade2bac5ad8065",
72 "rev": 0,
73 "user": "nobody"
74 }
75 ]
76
54 $ cat <<EOF >>a
77 $ cat <<EOF >>a
55 > a
78 > a
56 > a
79 > a
@@ -198,7 +198,7 b' Show an error if we use --options with a'
198 Show all commands + options
198 Show all commands + options
199 $ hg debugcommands
199 $ hg debugcommands
200 add: include, exclude, subrepos, dry-run
200 add: include, exclude, subrepos, dry-run
201 annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
201 annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude, template
202 clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
202 clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
203 commit: addremove, close-branch, amend, secret, edit, include, exclude, message, logfile, date, user, subrepos
203 commit: addremove, close-branch, amend, secret, edit, include, exclude, message, logfile, date, user, subrepos
204 diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
204 diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
General Comments 0
You need to be logged in to leave comments. Login now