Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 41512:16454d938299
grep: move writing of path outside of column loop
This will make the next patch simpler.
Differential Revision: https://phab.mercurial-scm.org/D5776
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 30 Jan 2019 16:59:31 -0800 |
parents | 72a9aacff645 |
children | 718e9b444d97 |
comparison
equal
deleted
inserted
replaced
41511:72a9aacff645 | 41512:16454d938299 |
---|---|
2865 try: | 2865 try: |
2866 return stringutil.binary(flog.read(ctx.filenode(fn))) | 2866 return stringutil.binary(flog.read(ctx.filenode(fn))) |
2867 except error.WdirUnsupported: | 2867 except error.WdirUnsupported: |
2868 return ctx[fn].isbinary() | 2868 return ctx[fn].isbinary() |
2869 | 2869 |
2870 fieldnamemap = {'filename': 'path', 'linenumber': 'lineno'} | 2870 fieldnamemap = {'linenumber': 'lineno'} |
2871 if diff: | 2871 if diff: |
2872 iter = difflinestates(pstates, states) | 2872 iter = difflinestates(pstates, states) |
2873 else: | 2873 else: |
2874 iter = [('', l) for l in states] | 2874 iter = [('', l) for l in states] |
2875 for change, l in iter: | 2875 for change, l in iter: |
2876 fm.startitem() | 2876 fm.startitem() |
2877 fm.context(ctx=ctx) | 2877 fm.context(ctx=ctx) |
2878 fm.data(node=fm.hexfunc(scmutil.binnode(ctx))) | 2878 fm.data(node=fm.hexfunc(scmutil.binnode(ctx))) |
2879 fm.write('path', '%s', fn, label='grep.filename') | |
2879 | 2880 |
2880 cols = [ | 2881 cols = [ |
2881 ('filename', '%s', fn, True), | |
2882 ('rev', '%d', rev, not plaingrep), | 2882 ('rev', '%d', rev, not plaingrep), |
2883 ('linenumber', '%d', l.linenum, opts.get('line_number')), | 2883 ('linenumber', '%d', l.linenum, opts.get('line_number')), |
2884 ] | 2884 ] |
2885 if diff: | 2885 if diff: |
2886 cols.append(('change', '%s', change, True)) | 2886 cols.append(('change', '%s', change, True)) |
2887 cols.extend([ | 2887 cols.extend([ |
2888 ('user', '%s', formatuser(ctx.user()), opts.get('user')), | 2888 ('user', '%s', formatuser(ctx.user()), opts.get('user')), |
2889 ('date', '%s', fm.formatdate(ctx.date(), datefmt), | 2889 ('date', '%s', fm.formatdate(ctx.date(), datefmt), |
2890 opts.get('date')), | 2890 opts.get('date')), |
2891 ]) | 2891 ]) |
2892 lastcol = next( | |
2893 name for name, fmt, data, cond in reversed(cols) if cond) | |
2894 for name, fmt, data, cond in cols: | 2892 for name, fmt, data, cond in cols: |
2893 if cond: | |
2894 fm.plain(sep, label='grep.sep') | |
2895 field = fieldnamemap.get(name, name) | 2895 field = fieldnamemap.get(name, name) |
2896 fm.condwrite(cond, field, fmt, data, label='grep.%s' % name) | 2896 fm.condwrite(cond, field, fmt, data, label='grep.%s' % name) |
2897 if cond and name != lastcol: | |
2898 fm.plain(sep, label='grep.sep') | |
2899 if not opts.get('files_with_matches'): | 2897 if not opts.get('files_with_matches'): |
2900 fm.plain(sep, label='grep.sep') | 2898 fm.plain(sep, label='grep.sep') |
2901 if not opts.get('text') and binary(): | 2899 if not opts.get('text') and binary(): |
2902 fm.plain(_(" Binary file matches")) | 2900 fm.plain(_(" Binary file matches")) |
2903 else: | 2901 else: |