grep: correct handling of matching lines without line ending (issue3050)
Matching lines without trailing '\n' was missing the last character.
That seems to have been an unintended side effect of 261a9f47b44b.
The test in dac14cc9711e documents the bad behaviour.
--- a/mercurial/commands.py Mon Oct 17 11:37:59 2011 +0200
+++ b/mercurial/commands.py Sun Oct 16 01:26:06 2011 +0200
@@ -2660,7 +2660,7 @@
mstart, mend = match.span()
linenum += body.count('\n', begin, mstart) + 1
lstart = body.rfind('\n', begin, mstart) + 1 or begin
- begin = body.find('\n', mend) + 1 or len(body)
+ begin = body.find('\n', mend) + 1 or len(body) + 1
lend = begin - 1
yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
--- a/tests/test-grep.t Mon Oct 17 11:37:59 2011 +0200
+++ b/tests/test-grep.t Sun Oct 16 01:26:06 2011 +0200
@@ -106,12 +106,8 @@
$ python -c 'fp = open("noeol", "wb"); fp.write("no infinite loop"); fp.close();'
$ hg ci -Amnoeol
adding noeol
-
-last character omitted in output to avoid infinite loop
-
$ hg grep loop
- noeol:4:no infinite loo
-
+ noeol:4:no infinite loop
$ cd ..