# HG changeset patch # User Mads Kiilerich # Date 2011-10-15 23:26:06 # Node ID 0e34699d6988d2cad9feea74f508c831f4a4ea76 # Parent 7fa471248185742ad1cba8704cf7888718f2157e 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2660,7 +2660,7 @@ def grep(ui, repo, pattern, *pats, **opt 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] diff --git a/tests/test-grep.t b/tests/test-grep.t --- a/tests/test-grep.t +++ b/tests/test-grep.t @@ -106,12 +106,8 @@ match in last "line" without newline $ 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 ..