All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Lodato <lodatom@gmail.com>
To: git@vger.kernel.org
Cc: Mark Lodato <lodatom@gmail.com>
Subject: [PATCH] grep -z: do not use NUL to after line number
Date: Fri, 20 Apr 2012 23:08:18 -0400	[thread overview]
Message-ID: <1334977698-31376-1-git-send-email-lodatom@gmail.com> (raw)

This makes `git grep -z' consistent with GNU `grep -Z' and also allows
the reader of the output to determine whether each line is a match,
context, or function.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
It seems like this should have been the original behavior, but I don't know if
it has been too long to change the output format, especially since this option
is used exclusively for processing by scripts.  Perhaps as a new option (-Z?)
or environment variable?

 grep.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/grep.c b/grep.c
index 190139c..82958f2 100644
--- a/grep.c
+++ b/grep.c
@@ -469,9 +469,9 @@ static void output_color(struct grep_opt *opt, const void *data, size_t size,
 		opt->output(opt, data, size);
 }
 
-static void output_sep(struct grep_opt *opt, char sign)
+static void output_sep(struct grep_opt *opt, char sign, int after_name)
 {
-	if (opt->null_following_name)
+	if (after_name && opt->null_following_name)
 		opt->output(opt, "\0", 1);
 	else
 		output_color(opt, &sign, 1, opt->color_sep);
@@ -762,13 +762,13 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 
 	if (!opt->heading && opt->pathname) {
 		output_color(opt, name, strlen(name), opt->color_filename);
-		output_sep(opt, sign);
+		output_sep(opt, sign, 1);
 	}
 	if (opt->linenum) {
 		char buf[32];
 		snprintf(buf, sizeof(buf), "%d", lno);
 		output_color(opt, buf, strlen(buf), opt->color_lineno);
-		output_sep(opt, sign);
+		output_sep(opt, sign, 0);
 	}
 	if (opt->color) {
 		regmatch_t match;
@@ -1152,7 +1152,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
 	if (opt->count && count) {
 		char buf[32];
 		output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
-		output_sep(opt, ':');
+		output_sep(opt, ':', 1);
 		snprintf(buf, sizeof(buf), "%u\n", count);
 		opt->output(opt, buf, strlen(buf));
 		return 1;
-- 
1.7.10

                 reply	other threads:[~2012-04-21  3:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1334977698-31376-1-git-send-email-lodatom@gmail.com \
    --to=lodatom@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.