# HG changeset patch # User FUJIWARA Katsunori # Date 1392461654 -32400 # Node ID fe849868fc5a6978fc69192f5e8c6fb35ff355eb # Parent 191a0ae3776784473fba0a54070742eb8a5fdd9e grep: exit loop immediately, if matching is found in the file for "hg grep -l" Before this patch, internal function "display()" of "hg grep" is not efficient for "-l"/"--files-with-matches", because loop is continued, even after the first matching is found in the specified file. This patch exits loop immediately, if matching is found for "--files-with-matches". In this case, "before is None" is equal to "opts.get('files_with_matches')". diff -r 191a0ae37767 -r fe849868fc5a mercurial/commands.py --- a/mercurial/commands.py Sat Feb 15 19:54:05 2014 +0900 +++ b/mercurial/commands.py Sat Feb 15 19:54:14 2014 +0900 @@ -3364,10 +3364,7 @@ cols.append((ui.shortuser(ctx.user()), 'grep.user')) if opts.get('date'): cols.append((datefunc(ctx.date()), 'grep.date')) - if opts.get('files_with_matches'): - if found: - continue - else: + if not opts.get('files_with_matches'): before = l.line[:l.colstart] match = l.line[l.colstart:l.colend] after = l.line[l.colend:] @@ -3385,6 +3382,8 @@ ui.write(after) ui.write(eol) found = True + if before is None: + break return found skip = {}