mirror of
https://github.com/facebook/sapling.git
synced 2024-10-13 02:07:31 +03:00
grep: correctly interpret the -l option when using biggrep
Summary: We'd fail to parse the data coming back from biggrep when the `-l` option was in use and just print out those lines as-is. This diff adds a check for this flag and handles it more appropriately. Reviewed By: quark-zju Differential Revision: D9518419 fbshipit-source-id: e00f0592adde2d9c3033ee6bc56c86ad27971beb
This commit is contained in:
parent
20a01dee08
commit
4e57dff6fe
@ -853,6 +853,7 @@ def grep(ui, repo, pattern, *pats, **opts):
|
|||||||
|
|
||||||
resultsbyfile = {}
|
resultsbyfile = {}
|
||||||
includelineno = opts.get("line_number")
|
includelineno = opts.get("line_number")
|
||||||
|
fileswithmatches = opts.get("files_with_matches")
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
try:
|
try:
|
||||||
@ -864,6 +865,8 @@ def grep(ui, repo, pattern, *pats, **opts):
|
|||||||
lineno = 0
|
lineno = 0
|
||||||
colno = 0
|
colno = 0
|
||||||
context = None
|
context = None
|
||||||
|
elif fileswithmatches:
|
||||||
|
filename = line
|
||||||
else:
|
else:
|
||||||
# If we couldn't parse the line, just pass it thru
|
# If we couldn't parse the line, just pass it thru
|
||||||
ui.write(line)
|
ui.write(line)
|
||||||
@ -882,9 +885,11 @@ def grep(ui, repo, pattern, *pats, **opts):
|
|||||||
if unescapedfilename not in resultsbyfile:
|
if unescapedfilename not in resultsbyfile:
|
||||||
resultsbyfile[unescapedfilename] = []
|
resultsbyfile[unescapedfilename] = []
|
||||||
|
|
||||||
# re-assemble the output, but omit the column number.
|
# re-assemble the output
|
||||||
# Take care with binary file matches!
|
if fileswithmatches:
|
||||||
if lineno == 0 and colno == 0 and context is None:
|
resultsbyfile[unescapedfilename].append("%s\n" % filename)
|
||||||
|
elif lineno == 0 and colno == 0 and context is None:
|
||||||
|
# Take care with binary file matches!
|
||||||
resultsbyfile[unescapedfilename].append(
|
resultsbyfile[unescapedfilename].append(
|
||||||
"Binary file %s matches\n" % filename
|
"Binary file %s matches\n" % filename
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user