comparison mercurial/commands.py @ 22477:3c8ae79eacb0

annotate: build format string separately from annotation data This prepares for porting to generic templater API. Note that we cannot use '%*s' to pad white spaces because it doesn't take into account character widths, as described in 4f5a6df2af92.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 29 Aug 2014 05:36:52 +0200
parents 75e166b82c7a
children a6b1413511f1
comparison
equal deleted inserted replaced
22476:a0829ec34dbd 22477:3c8ae79eacb0
311 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) 311 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
312 continue 312 continue
313 313
314 lines = fctx.annotate(follow=follow, linenumber=linenumber, 314 lines = fctx.annotate(follow=follow, linenumber=linenumber,
315 diffopts=diffopts) 315 diffopts=diffopts)
316 formats = []
316 pieces = [] 317 pieces = []
317 318
318 for f, sep in funcmap: 319 for f, sep in funcmap:
319 l = [f(n) for n, dummy in lines] 320 l = [f(n) for n, dummy in lines]
320 if l: 321 if l:
321 sized = [(x, encoding.colwidth(x)) for x in l] 322 sized = [(x, encoding.colwidth(x)) for x in l]
322 ml = max([w for x, w in sized]) 323 ml = max([w for x, w in sized])
323 pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x) 324 formats.append([sep + ' ' * (ml - w) + '%s'
324 for x, w in sized]) 325 for x, w in sized])
325 326 pieces.append(l)
326 for p, l in zip(zip(*pieces), lines): 327
327 ui.write("%s: %s" % ("".join(p), l[1])) 328 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
329 ui.write("".join(f) % p)
330 ui.write(": %s" % l[1])
328 331
329 if lines and not lines[-1][1].endswith('\n'): 332 if lines and not lines[-1][1].endswith('\n'):
330 ui.write('\n') 333 ui.write('\n')
331 334
332 @command('archive', 335 @command('archive',