comparison mercurial/commands.py @ 38651:5e4027db52f4

grep: add config knob to enable/disable the default wdir search This allows us to conditionally enable the new behavior to unbreak python-hglib. See the next patch. The config option is undocumented since the --all-files is still experimental and isn't fully implemented. It can be moved to [experimental] if that's preferred. Differential Revision: https://phab.mercurial-scm.org/D3918
author Yuya Nishihara <yuya@tcha.org>
date Wed, 11 Jul 2018 21:51:47 +0900
parents eba69ddd4e52
children bfcd5c7cbf9a
comparison
equal deleted inserted replaced
38650:eba69ddd4e52 38651:5e4027db52f4
2499 ('l', 'files-with-matches', None, 2499 ('l', 'files-with-matches', None,
2500 _('print only filenames and revisions that match')), 2500 _('print only filenames and revisions that match')),
2501 ('n', 'line-number', None, _('print matching line numbers')), 2501 ('n', 'line-number', None, _('print matching line numbers')),
2502 ('r', 'rev', [], 2502 ('r', 'rev', [],
2503 _('only search files changed within revision range'), _('REV')), 2503 _('only search files changed within revision range'), _('REV')),
2504 ('', 'all-files', False, 2504 ('', 'all-files', None,
2505 _('include all files in the changeset while grepping (EXPERIMENTAL)')), 2505 _('include all files in the changeset while grepping (EXPERIMENTAL)')),
2506 ('u', 'user', None, _('list the author (long with -v)')), 2506 ('u', 'user', None, _('list the author (long with -v)')),
2507 ('d', 'date', None, _('list the date (short with -q)')), 2507 ('d', 'date', None, _('list the date (short with -q)')),
2508 ] + formatteropts + walkopts, 2508 ] + formatteropts + walkopts,
2509 _('[OPTION]... PATTERN [FILE]...'), 2509 _('[OPTION]... PATTERN [FILE]...'),
2533 """ 2533 """
2534 opts = pycompat.byteskwargs(opts) 2534 opts = pycompat.byteskwargs(opts)
2535 diff = opts.get('all') or opts.get('diff') 2535 diff = opts.get('all') or opts.get('diff')
2536 if diff and opts.get('all_files'): 2536 if diff and opts.get('all_files'):
2537 raise error.Abort(_('--diff and --all-files are mutually exclusive')) 2537 raise error.Abort(_('--diff and --all-files are mutually exclusive'))
2538 # TODO: remove "not opts.get('rev')" if --all-files -rMULTIREV gets working
2539 if opts.get('all_files') is None and not opts.get('rev') and not diff:
2540 # experimental config: commands.grep.all-files
2541 opts['all_files'] = ui.configbool('commands', 'grep.all-files')
2538 if opts.get('all_files') and not opts.get('rev'): 2542 if opts.get('all_files') and not opts.get('rev'):
2539 opts['rev'] = ['wdir()'] 2543 opts['rev'] = ['wdir()']
2540 2544
2541 reflags = re.M 2545 reflags = re.M
2542 if opts.get('ignore_case'): 2546 if opts.get('ignore_case'):
2547 ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)) 2551 ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst))
2548 return 1 2552 return 1
2549 sep, eol = ':', '\n' 2553 sep, eol = ':', '\n'
2550 if opts.get('print0'): 2554 if opts.get('print0'):
2551 sep = eol = '\0' 2555 sep = eol = '\0'
2552
2553 if not opts.get('rev') and not diff:
2554 opts['rev'] = ["wdir()"]
2555 opts['all_files'] = True
2556 2556
2557 getfile = util.lrucachefunc(repo.file) 2557 getfile = util.lrucachefunc(repo.file)
2558 2558
2559 def matchlines(body): 2559 def matchlines(body):
2560 begin = 0 2560 begin = 0