Mercurial > hg
comparison mercurial/commands.py @ 20838:fe849868fc5a
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')".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 15 Feb 2014 19:54:14 +0900 |
parents | 191a0ae37767 |
children | 6500a2eebee8 |
comparison
equal
deleted
inserted
replaced
20837:191a0ae37767 | 20838:fe849868fc5a |
---|---|
3362 cols.append((change, 'grep.change')) | 3362 cols.append((change, 'grep.change')) |
3363 if opts.get('user'): | 3363 if opts.get('user'): |
3364 cols.append((ui.shortuser(ctx.user()), 'grep.user')) | 3364 cols.append((ui.shortuser(ctx.user()), 'grep.user')) |
3365 if opts.get('date'): | 3365 if opts.get('date'): |
3366 cols.append((datefunc(ctx.date()), 'grep.date')) | 3366 cols.append((datefunc(ctx.date()), 'grep.date')) |
3367 if opts.get('files_with_matches'): | 3367 if not opts.get('files_with_matches'): |
3368 if found: | |
3369 continue | |
3370 else: | |
3371 before = l.line[:l.colstart] | 3368 before = l.line[:l.colstart] |
3372 match = l.line[l.colstart:l.colend] | 3369 match = l.line[l.colstart:l.colend] |
3373 after = l.line[l.colend:] | 3370 after = l.line[l.colend:] |
3374 for col, label in cols[:-1]: | 3371 for col, label in cols[:-1]: |
3375 ui.write(col, label=label) | 3372 ui.write(col, label=label) |
3383 ui.write(before) | 3380 ui.write(before) |
3384 ui.write(match, label='grep.match') | 3381 ui.write(match, label='grep.match') |
3385 ui.write(after) | 3382 ui.write(after) |
3386 ui.write(eol) | 3383 ui.write(eol) |
3387 found = True | 3384 found = True |
3385 if before is None: | |
3386 break | |
3388 return found | 3387 return found |
3389 | 3388 |
3390 skip = {} | 3389 skip = {} |
3391 revfiles = {} | 3390 revfiles = {} |
3392 matchfn = scmutil.match(repo[None], pats, opts) | 3391 matchfn = scmutil.match(repo[None], pats, opts) |