[PATCH 5 of 9] grep: correctly handle multiline matches with several expressions
Pierre-Yves David
pierre-yves.david at logilab.fr
Tue Oct 16 06:43:12 CDT 2012
On Sun, Oct 14, 2012 at 10:54:22PM +0200, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1349693025 -7200
> # Node ID a83911a11e922e7b941e1c1dd6c66a6654a6b069
> # Parent 06edbeb509881597122b46de831da4332076c4a1
> grep: correctly handle multiline matches with several expressions
This changesets add non-trivial logic and should be better described
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2953,6 +2953,17 @@
> lstart = body.rfind('\n', begin, mstart) + 1 or begin
> begin = body.find('\n', mend) + 1 or len(body) + 1
> lend = begin - 1
> + # We need to be careful with multiline regexps. Since we pick
> + # the match that is seen earlier in the file, it's possible
> + # that a multiline regexp spans the same line as the match we
> + # picked but includes the following lines. In that case we'd like
> + # to pick the longer regexp.
This comment is welcome, but the exacte trouble we want to avoid is not cristal clear (see below)
> + for m in matches:
> + if m != match:
> + s, e = m.span()
> + if lstart <= s <= lend and e > lend:
> + begin = body.find('\n', e) + 1 or len(body) + 1
> + lend = begin - 1
> yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
>
> class linestate(object):
> diff --git a/tests/test-grep.t b/tests/test-grep.t
> --- a/tests/test-grep.t
> +++ b/tests/test-grep.t
> @@ -31,6 +31,9 @@
> port:4:export
> port:4:vaportight
> port:4:import/export
> + $ hg grep -e vap -e 'ght\nimp' port
> + port:4:vaportight
> + import/export
> $ hg grep --no-filename port port
> 4:export
> 4:vaportight
What about your document this testcase a bit more? We example output of what we
are trying to avoid.
--
Pierre-Yves David
http://www.logilab.fr/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20121016/d2c25ea4/attachment.pgp>
More information about the Mercurial-devel
mailing list