git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] grep: fix colouring of matches with zero length
Date: Mon, 01 Jun 2009 23:53:05 +0200	[thread overview]
Message-ID: <4A244DC1.1090801@lsrfire.ath.cx> (raw)
In-Reply-To: <7voct7k61r.fsf@alter.siamese.dyndns.org>

Junio C Hamano schrieb:
> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> 
>> The first hunk fixes match colouring if the patterns is the empty string.
>> Such a pattern matches the whole line,...
> 
> Hmmm...
> 
> An empty pattern may have to produce a match with any line, but I do not
> think it should match the whole line.  GNU seems to agree with me.
> 
> 	echo foo | grep --color -e ''
>         echo foo | grep --color -F -e ''
>         echo foo | grep --color -e '.*'
>         echo foo | grep --color -F -e 'foo'
> 
> The first two are uncoloured (but still show matches).

You're right, and matching the zero-length string at the beginning of the
line actually makes sense.  Corrected patch below.


If a zero-length match is encountered, break out of loop and show the rest
of the line uncoloured.  Otherwise we'd be looping forever, trying to make
progress by advancing the pointer by zero characters.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 grep.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/grep.c b/grep.c
index cc6d5b0..7bf4a60 100644
--- a/grep.c
+++ b/grep.c
@@ -500,6 +500,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 
 		*eol = '\0';
 		while (next_match(opt, bol, eol, ctx, &match, eflags)) {
+			if (match.rm_so == match.rm_eo)
+				break;
 			printf("%.*s%s%.*s%s",
 			       (int)match.rm_so, bol,
 			       opt->color_match,
-- 
1.6.3.1

      reply	other threads:[~2009-06-01 21:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-01 16:46 [PATCH] grep: fix colouring of matches with zero length René Scharfe
2009-06-01 21:17 ` Junio C Hamano
2009-06-01 21:53   ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A244DC1.1090801@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).