aboutsummaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRaphael Zimmerer <killekulla@rdrz.de>2008-10-01 18:11:15 +0200
committerShawn O. Pearce <spearce@spearce.org>2008-10-01 09:14:54 -0700
commit83caecca2f0805d440099d19011fdedc2b3467a5 (patch)
treefd5ba5878c5058991a7e9e3bde78a8908221e500 /grep.c
parent5e22e21769454857e00bc55be1f2eef8d873ba72 (diff)
downloadgit-83caecca2f0805d440099d19011fdedc2b3467a5.tar.gz
git-83caecca2f0805d440099d19011fdedc2b3467a5.tar.xz
git grep: Add "-z/--null" option as in GNU's grep.
Here's a trivial patch that adds "-z" and "--null" options to "git grep". It was discussed on the mailing-list that git's "-z" convention should be used instead of GNU grep's "-Z". So things like 'git grep -l -z "$FOO" | xargs -0 sed -i "s/$FOO/$BOO/"' do work now. Signed-off-by: Raphael Zimmerer <killekulla@rdrz.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/grep.c b/grep.c
index 706351197..e2c190a7f 100644
--- a/grep.c
+++ b/grep.c
@@ -239,6 +239,8 @@ static int word_char(char ch)
static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
const char *name, unsigned lno, char sign)
{
+ if (opt->null_following_name)
+ sign = '\0';
if (opt->pathname)
printf("%s%c", name, sign);
if (opt->linenum)
@@ -246,6 +248,11 @@ static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
printf("%.*s\n", (int)(eol-bol), bol);
}
+static void show_name(struct grep_opt *opt, const char *name)
+{
+ printf("%s%c", name, opt->null_following_name ? '\0' : '\n');
+}
+
static int fixmatch(const char *pattern, char *line, regmatch_t *match)
{
char *hit = strstr(line, pattern);
@@ -489,7 +496,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
return 1;
}
if (opt->name_only) {
- printf("%s\n", name);
+ show_name(opt, name);
return 1;
}
/* Hit at this line. If we haven't shown the
@@ -555,7 +562,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
return 0;
if (opt->unmatch_name_only) {
/* We did not see any hit, so we want to show this */
- printf("%s\n", name);
+ show_name(opt, name);
return 1;
}
@@ -565,7 +572,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
* make it another option? For now suppress them.
*/
if (opt->count && count)
- printf("%s:%u\n", name, count);
+ printf("%s%c%u\n", name,
+ opt->null_following_name ? '\0' : ':', count);
return !!last_hit;
}