{"thread":{"id":"30300","subject":"[PATCH] grep -z: do not use NUL to after line number","startedAt":"2012-04-21T03:08:18Z","lastAt":"2012-04-21T03:08:18Z","messageCount":1,"participants":["Mark Lodato"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"189791","messageId":"1334977698-31376-1-git-send-email-lodatom@gmail.com","threadId":"30300","inReplyTo":null,"subject":"[PATCH] grep -z: do not use NUL to after line number","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2012-04-21T03:08:18Z","receivedAt":"2012-04-21T03:08:18Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"This makes `git grep -z' consistent with GNU `grep -Z' and also allows\nthe reader of the output to determine whether each line is a match,\ncontext, or function.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\nIt seems like this should have been the original behavior, but I don't know if\nit has been too long to change the output format, especially since this option\nis used exclusively for processing by scripts.  Perhaps as a new option (-Z?)\nor environment variable?\n\n grep.c |   10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 190139c..82958f2 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -469,9 +469,9 @@ static void output_color(struct grep_opt *opt, const void *data, size_t size,\n \t\topt->output(opt, data, size);\n }\n \n-static void output_sep(struct grep_opt *opt, char sign)\n+static void output_sep(struct grep_opt *opt, char sign, int after_name)\n {\n-\tif (opt->null_following_name)\n+\tif (after_name && opt->null_following_name)\n \t\topt->output(opt, \"\\0\", 1);\n \telse\n \t\toutput_color(opt, &sign, 1, opt->color_sep);\n@@ -762,13 +762,13 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \n \tif (!opt->heading && opt->pathname) {\n \t\toutput_color(opt, name, strlen(name), opt->color_filename);\n-\t\toutput_sep(opt, sign);\n+\t\toutput_sep(opt, sign, 1);\n \t}\n \tif (opt->linenum) {\n \t\tchar buf[32];\n \t\tsnprintf(buf, sizeof(buf), \"%d\", lno);\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n-\t\toutput_sep(opt, sign);\n+\t\toutput_sep(opt, sign, 0);\n \t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n@@ -1152,7 +1152,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tif (opt->count && count) {\n \t\tchar buf[32];\n \t\toutput_color(opt, gs->name, strlen(gs->name), opt->color_filename);\n-\t\toutput_sep(opt, ':');\n+\t\toutput_sep(opt, ':', 1);\n \t\tsnprintf(buf, sizeof(buf), \"%u\\n\", count);\n \t\topt->output(opt, buf, strlen(buf));\n \t\treturn 1;\n-- \n1.7.10\n"}]}