# HG changeset patch # User Yuya Nishihara # Date 1471499526 -32400 # Node ID 0418cdf67efb3c2face162a91eaa5d1def7193f9 # Parent 37d838e8eb0b40bfb6bfdc902cacdb3d62a0ce60 grep: build list of all columns regardless of display options These columns should always be available in JSON or template outputs. The "change" column is excluded because it has no useful data unless --all is specified. diff -r 37d838e8eb0b -r 0418cdf67efb mercurial/commands.py --- a/mercurial/commands.py Thu Aug 18 14:23:29 2016 +0900 +++ b/mercurial/commands.py Thu Aug 18 14:52:06 2016 +0900 @@ -4397,20 +4397,23 @@ else: iter = [('', l) for l in states] for change, l in iter: - cols = [(fn, 'filename'), (str(rev), 'rev')] - - if opts.get('line_number'): - cols.append((str(l.linenum), 'linenumber')) + cols = [ + ('filename', fn, True), + ('rev', str(rev), True), + ('linenumber', str(l.linenum), opts.get('line_number')), + ] if opts.get('all'): - cols.append((change, 'change')) - if opts.get('user'): - cols.append((ui.shortuser(ctx.user()), 'user')) - if opts.get('date'): - cols.append((datefunc(ctx.date()), 'date')) - for col, field in cols[:-1]: - ui.write(col, label='grep.%s' % field) - ui.write(sep, label='grep.sep') - ui.write(cols[-1][0], label='grep.%s' % cols[-1][1]) + cols.append(('change', change, True)) + cols.extend([ + ('user', ui.shortuser(ctx.user()), opts.get('user')), + ('date', datefunc(ctx.date()), opts.get('date')), + ]) + lastcol = next(name for name, data, cond in reversed(cols) if cond) + for name, data, cond in cols: + if cond: + ui.write(data, label='grep.%s' % name) + if cond and name != lastcol: + ui.write(sep, label='grep.sep') if not opts.get('files_with_matches'): ui.write(sep, label='grep.sep') if not opts.get('text') and binary():