##// END OF EJS Templates
grep: avoid reassigning byteskwargs to strkwargs...
Matt Harbison -
r51554:4a73df6e default
parent child Browse files
Show More
@@ -3529,22 +3529,20 b' def grep(ui, repo, pattern, *pats, **opt'
3529
3529
3530 """
3530 """
3531 cmdutil.check_incompatible_arguments(opts, 'all_files', ['all', 'diff'])
3531 cmdutil.check_incompatible_arguments(opts, 'all_files', ['all', 'diff'])
3532 opts = pycompat.byteskwargs(opts)
3532
3533 diff = opts.get(b'all') or opts.get(b'diff')
3533 diff = opts.get('all') or opts.get('diff')
3534 follow = opts.get(b'follow')
3534 follow = opts.get('follow')
3535 if opts.get(b'all_files') is None and not diff:
3535 if opts.get('all_files') is None and not diff:
3536 opts[b'all_files'] = True
3536 opts['all_files'] = True
3537 plaingrep = (
3537 plaingrep = (
3538 opts.get(b'all_files')
3538 opts.get('all_files') and not opts.get('rev') and not opts.get('follow')
3539 and not opts.get(b'rev')
3540 and not opts.get(b'follow')
3541 )
3539 )
3542 all_files = opts.get(b'all_files')
3540 all_files = opts.get('all_files')
3543 if plaingrep:
3541 if plaingrep:
3544 opts[b'rev'] = [b'wdir()']
3542 opts['rev'] = [b'wdir()']
3545
3543
3546 reflags = re.M
3544 reflags = re.M
3547 if opts.get(b'ignore_case'):
3545 if opts.get('ignore_case'):
3548 reflags |= re.I
3546 reflags |= re.I
3549 try:
3547 try:
3550 regexp = util.re.compile(pattern, reflags)
3548 regexp = util.re.compile(pattern, reflags)
@@ -3555,7 +3553,7 b' def grep(ui, repo, pattern, *pats, **opt'
3555 )
3553 )
3556 return 1
3554 return 1
3557 sep, eol = b':', b'\n'
3555 sep, eol = b':', b'\n'
3558 if opts.get(b'print0'):
3556 if opts.get('print0'):
3559 sep = eol = b'\0'
3557 sep = eol = b'\0'
3560
3558
3561 searcher = grepmod.grepsearcher(
3559 searcher = grepmod.grepsearcher(
@@ -3603,7 +3601,7 b' def grep(ui, repo, pattern, *pats, **opt'
3603 b'linenumber',
3601 b'linenumber',
3604 b'%d',
3602 b'%d',
3605 l.linenum,
3603 l.linenum,
3606 opts.get(b'line_number'),
3604 opts.get('line_number'),
3607 b'',
3605 b'',
3608 ),
3606 ),
3609 ]
3607 ]
@@ -3625,14 +3623,14 b' def grep(ui, repo, pattern, *pats, **opt'
3625 b'user',
3623 b'user',
3626 b'%s',
3624 b'%s',
3627 formatuser(ctx.user()),
3625 formatuser(ctx.user()),
3628 opts.get(b'user'),
3626 opts.get('user'),
3629 b'',
3627 b'',
3630 ),
3628 ),
3631 (
3629 (
3632 b'date',
3630 b'date',
3633 b'%s',
3631 b'%s',
3634 fm.formatdate(ctx.date(), datefmt),
3632 fm.formatdate(ctx.date(), datefmt),
3635 opts.get(b'date'),
3633 opts.get('date'),
3636 b'',
3634 b'',
3637 ),
3635 ),
3638 ]
3636 ]
@@ -3643,15 +3641,15 b' def grep(ui, repo, pattern, *pats, **opt'
3643 field = fieldnamemap.get(name, name)
3641 field = fieldnamemap.get(name, name)
3644 label = extra_label + (b'grep.%s' % name)
3642 label = extra_label + (b'grep.%s' % name)
3645 fm.condwrite(cond, field, fmt, data, label=label)
3643 fm.condwrite(cond, field, fmt, data, label=label)
3646 if not opts.get(b'files_with_matches'):
3644 if not opts.get('files_with_matches'):
3647 fm.plain(sep, label=b'grep.sep')
3645 fm.plain(sep, label=b'grep.sep')
3648 if not opts.get(b'text') and binary():
3646 if not opts.get('text') and binary():
3649 fm.plain(_(b" Binary file matches"))
3647 fm.plain(_(b" Binary file matches"))
3650 else:
3648 else:
3651 displaymatches(fm.nested(b'texts', tmpl=b'{text}'), l)
3649 displaymatches(fm.nested(b'texts', tmpl=b'{text}'), l)
3652 fm.plain(eol)
3650 fm.plain(eol)
3653 found = True
3651 found = True
3654 if opts.get(b'files_with_matches'):
3652 if opts.get('files_with_matches'):
3655 break
3653 break
3656 return found
3654 return found
3657
3655
@@ -3677,9 +3675,9 b' def grep(ui, repo, pattern, *pats, **opt'
3677 wopts = logcmdutil.walkopts(
3675 wopts = logcmdutil.walkopts(
3678 pats=pats,
3676 pats=pats,
3679 opts=opts,
3677 opts=opts,
3680 revspec=opts[b'rev'],
3678 revspec=opts['rev'],
3681 include_pats=opts[b'include'],
3679 include_pats=opts['include'],
3682 exclude_pats=opts[b'exclude'],
3680 exclude_pats=opts['exclude'],
3683 follow=follow,
3681 follow=follow,
3684 force_changelog_traversal=all_files,
3682 force_changelog_traversal=all_files,
3685 filter_revisions_by_pats=not all_files,
3683 filter_revisions_by_pats=not all_files,
@@ -3687,7 +3685,7 b' def grep(ui, repo, pattern, *pats, **opt'
3687 revs, makefilematcher = logcmdutil.makewalker(repo, wopts)
3685 revs, makefilematcher = logcmdutil.makewalker(repo, wopts)
3688
3686
3689 ui.pager(b'grep')
3687 ui.pager(b'grep')
3690 fm = ui.formatter(b'grep', opts)
3688 fm = ui.formatter(b'grep', pycompat.byteskwargs(opts))
3691 for fn, ctx, pstates, states in searcher.searchfiles(revs, makefilematcher):
3689 for fn, ctx, pstates, states in searcher.searchfiles(revs, makefilematcher):
3692 r = display(fm, fn, ctx, pstates, states)
3690 r = display(fm, fn, ctx, pstates, states)
3693 found = found or r
3691 found = found or r
General Comments 0
You need to be logged in to leave comments. Login now