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 ..