mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-01-08 16:14:26 +00:00
grep: move nested func out to the class
This is in preparation for adding jobs support. The nested function is referenced in the options object which can't be pickled, so pull it out into a static method instead. Change-Id: I280ed2bf26390a0203925517a0d17c13053becaa Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/297983 Reviewed-by: Michael Mortensen <mmortensen@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
7b586f231b
commit
45ad1541c5
@ -62,11 +62,8 @@ contain a line that matches both expressions:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _Options(self, p):
|
@staticmethod
|
||||||
def carry(option,
|
def _carry_option(_option, opt_str, value, parser):
|
||||||
opt_str,
|
|
||||||
value,
|
|
||||||
parser):
|
|
||||||
pt = getattr(parser.values, 'cmd_argv', None)
|
pt = getattr(parser.values, 'cmd_argv', None)
|
||||||
if pt is None:
|
if pt is None:
|
||||||
pt = []
|
pt = []
|
||||||
@ -82,9 +79,10 @@ contain a line that matches both expressions:
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
pt.append(value)
|
pt.append(value)
|
||||||
|
|
||||||
|
def _Options(self, p):
|
||||||
g = p.add_option_group('Sources')
|
g = p.add_option_group('Sources')
|
||||||
g.add_option('--cached',
|
g.add_option('--cached',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Search the index, instead of the work tree')
|
help='Search the index, instead of the work tree')
|
||||||
g.add_option('-r', '--revision',
|
g.add_option('-r', '--revision',
|
||||||
dest='revision', action='append', metavar='TREEish',
|
dest='revision', action='append', metavar='TREEish',
|
||||||
@ -92,66 +90,66 @@ contain a line that matches both expressions:
|
|||||||
|
|
||||||
g = p.add_option_group('Pattern')
|
g = p.add_option_group('Pattern')
|
||||||
g.add_option('-e',
|
g.add_option('-e',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
metavar='PATTERN', type='str',
|
metavar='PATTERN', type='str',
|
||||||
help='Pattern to search for')
|
help='Pattern to search for')
|
||||||
g.add_option('-i', '--ignore-case',
|
g.add_option('-i', '--ignore-case',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Ignore case differences')
|
help='Ignore case differences')
|
||||||
g.add_option('-a', '--text',
|
g.add_option('-a', '--text',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help="Process binary files as if they were text")
|
help="Process binary files as if they were text")
|
||||||
g.add_option('-I',
|
g.add_option('-I',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help="Don't match the pattern in binary files")
|
help="Don't match the pattern in binary files")
|
||||||
g.add_option('-w', '--word-regexp',
|
g.add_option('-w', '--word-regexp',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Match the pattern only at word boundaries')
|
help='Match the pattern only at word boundaries')
|
||||||
g.add_option('-v', '--invert-match',
|
g.add_option('-v', '--invert-match',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Select non-matching lines')
|
help='Select non-matching lines')
|
||||||
g.add_option('-G', '--basic-regexp',
|
g.add_option('-G', '--basic-regexp',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Use POSIX basic regexp for patterns (default)')
|
help='Use POSIX basic regexp for patterns (default)')
|
||||||
g.add_option('-E', '--extended-regexp',
|
g.add_option('-E', '--extended-regexp',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Use POSIX extended regexp for patterns')
|
help='Use POSIX extended regexp for patterns')
|
||||||
g.add_option('-F', '--fixed-strings',
|
g.add_option('-F', '--fixed-strings',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Use fixed strings (not regexp) for pattern')
|
help='Use fixed strings (not regexp) for pattern')
|
||||||
|
|
||||||
g = p.add_option_group('Pattern Grouping')
|
g = p.add_option_group('Pattern Grouping')
|
||||||
g.add_option('--all-match',
|
g.add_option('--all-match',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Limit match to lines that have all patterns')
|
help='Limit match to lines that have all patterns')
|
||||||
g.add_option('--and', '--or', '--not',
|
g.add_option('--and', '--or', '--not',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Boolean operators to combine patterns')
|
help='Boolean operators to combine patterns')
|
||||||
g.add_option('-(', '-)',
|
g.add_option('-(', '-)',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Boolean operator grouping')
|
help='Boolean operator grouping')
|
||||||
|
|
||||||
g = p.add_option_group('Output')
|
g = p.add_option_group('Output')
|
||||||
g.add_option('-n',
|
g.add_option('-n',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Prefix the line number to matching lines')
|
help='Prefix the line number to matching lines')
|
||||||
g.add_option('-C',
|
g.add_option('-C',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
metavar='CONTEXT', type='str',
|
metavar='CONTEXT', type='str',
|
||||||
help='Show CONTEXT lines around match')
|
help='Show CONTEXT lines around match')
|
||||||
g.add_option('-B',
|
g.add_option('-B',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
metavar='CONTEXT', type='str',
|
metavar='CONTEXT', type='str',
|
||||||
help='Show CONTEXT lines before match')
|
help='Show CONTEXT lines before match')
|
||||||
g.add_option('-A',
|
g.add_option('-A',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
metavar='CONTEXT', type='str',
|
metavar='CONTEXT', type='str',
|
||||||
help='Show CONTEXT lines after match')
|
help='Show CONTEXT lines after match')
|
||||||
g.add_option('-l', '--name-only', '--files-with-matches',
|
g.add_option('-l', '--name-only', '--files-with-matches',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Show only file names containing matching lines')
|
help='Show only file names containing matching lines')
|
||||||
g.add_option('-L', '--files-without-match',
|
g.add_option('-L', '--files-without-match',
|
||||||
action='callback', callback=carry,
|
action='callback', callback=self._carry_option,
|
||||||
help='Show only file names not containing matching lines')
|
help='Show only file names not containing matching lines')
|
||||||
|
|
||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
|
Loading…
Reference in New Issue
Block a user