Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 29863:0418cdf67efb
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 18 Aug 2016 14:52:06 +0900 |
parents | 37d838e8eb0b |
children | 33461139c31c |
comparison
equal
deleted
inserted
replaced
29862:37d838e8eb0b | 29863:0418cdf67efb |
---|---|
4395 if opts.get('all'): | 4395 if opts.get('all'): |
4396 iter = difflinestates(pstates, states) | 4396 iter = difflinestates(pstates, states) |
4397 else: | 4397 else: |
4398 iter = [('', l) for l in states] | 4398 iter = [('', l) for l in states] |
4399 for change, l in iter: | 4399 for change, l in iter: |
4400 cols = [(fn, 'filename'), (str(rev), 'rev')] | 4400 cols = [ |
4401 | 4401 ('filename', fn, True), |
4402 if opts.get('line_number'): | 4402 ('rev', str(rev), True), |
4403 cols.append((str(l.linenum), 'linenumber')) | 4403 ('linenumber', str(l.linenum), opts.get('line_number')), |
4404 ] | |
4404 if opts.get('all'): | 4405 if opts.get('all'): |
4405 cols.append((change, 'change')) | 4406 cols.append(('change', change, True)) |
4406 if opts.get('user'): | 4407 cols.extend([ |
4407 cols.append((ui.shortuser(ctx.user()), 'user')) | 4408 ('user', ui.shortuser(ctx.user()), opts.get('user')), |
4408 if opts.get('date'): | 4409 ('date', datefunc(ctx.date()), opts.get('date')), |
4409 cols.append((datefunc(ctx.date()), 'date')) | 4410 ]) |
4410 for col, field in cols[:-1]: | 4411 lastcol = next(name for name, data, cond in reversed(cols) if cond) |
4411 ui.write(col, label='grep.%s' % field) | 4412 for name, data, cond in cols: |
4412 ui.write(sep, label='grep.sep') | 4413 if cond: |
4413 ui.write(cols[-1][0], label='grep.%s' % cols[-1][1]) | 4414 ui.write(data, label='grep.%s' % name) |
4415 if cond and name != lastcol: | |
4416 ui.write(sep, label='grep.sep') | |
4414 if not opts.get('files_with_matches'): | 4417 if not opts.get('files_with_matches'): |
4415 ui.write(sep, label='grep.sep') | 4418 ui.write(sep, label='grep.sep') |
4416 if not opts.get('text') and binary(): | 4419 if not opts.get('text') and binary(): |
4417 ui.write(_(" Binary file matches")) | 4420 ui.write(_(" Binary file matches")) |
4418 else: | 4421 else: |