# HG changeset patch # User Yuya Nishihara # Date 1410878424 -32400 # Node ID 5d9e46d93c1d3b926a6752eaae554f81d18cc962 # Parent a6b1413511f120f568ad2ce9bcb1446186cfceb0 annotate: split functions to get data without applying text formatting This prepares for porting to generic templater API, where raw data should be passed to the formatter. makefunc() is necessary to build closure in list comprehension. diff -r a6b1413511f1 -r 5d9e46d93c1d mercurial/commands.py --- a/mercurial/commands.py Fri Aug 29 06:19:32 2014 +0200 +++ b/mercurial/commands.py Tue Sep 16 23:40:24 2014 +0900 @@ -275,15 +275,14 @@ opts['file'] = True datefunc = ui.quiet and util.shortdate or util.datestr - getdate = util.cachefunc(lambda x: datefunc(x[0].date())) hexfn = ui.debugflag and hex or short - 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()), - ('line_number', ':', lambda x: str(x[1])), + opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), + ('number', ' ', lambda x: x[0].rev(), str), + ('changeset', ' ', lambda x: hexfn(x[0].node()), str), + ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), + ('file', ' ', lambda x: x[0].path(), str), + ('line_number', ':', lambda x: x[1], str), ] if (not opts.get('user') and not opts.get('changeset') @@ -294,7 +293,10 @@ if linenumber and (not opts.get('changeset')) and (not opts.get('number')): raise util.Abort(_('at least one of -n/-c is required for -l')) - funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)] + def makefunc(get, fmt): + return lambda x: fmt(get(x)) + funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap + if opts.get(op)] funcmap[0] = (funcmap[0][0], '') # no separator in front of first column def bad(x, y):