Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 17923:1e6b5faf9d4e
grep: don't search past the end of the searched string
'*' causes the resulting RE to match 0 or more repetitions of the preceding RE:
>>> bool(re.search('.*', ''))
>>> True
This causes an infinite loop because currently we're only checking if there was
a match without looking at where we are in the searched string.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Mon, 12 Nov 2012 19:27:03 +0200 |
parents | 7f5dab94e48c |
children | c8ffde272653 |
comparison
equal
deleted
inserted
replaced
17922:7f5dab94e48c | 17923:1e6b5faf9d4e |
---|---|
2934 getfile = util.lrucachefunc(repo.file) | 2934 getfile = util.lrucachefunc(repo.file) |
2935 | 2935 |
2936 def matchlines(body): | 2936 def matchlines(body): |
2937 begin = 0 | 2937 begin = 0 |
2938 linenum = 0 | 2938 linenum = 0 |
2939 while True: | 2939 while True and begin < len(body): |
2940 match = regexp.search(body, begin) | 2940 match = regexp.search(body, begin) |
2941 if not match: | 2941 if not match: |
2942 break | 2942 break |
2943 mstart, mend = match.span() | 2943 mstart, mend = match.span() |
2944 linenum += body.count('\n', begin, mstart) + 1 | 2944 linenum += body.count('\n', begin, mstart) + 1 |