author | Junio C Hamano <gitster@pobox.com> | |
Tue, 19 Jan 2010 01:03:34 +0000 (17:03 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 19 Jan 2010 01:03:34 +0000 (17:03 -0800) |
* jm/maint-1.6.5-grep-NUL-terminate:
grep: NUL terminate input from a file
grep: NUL terminate input from a file
1 | 2 | |||
---|---|---|---|---|
builtin-grep.c | patch | | diff1 | | diff2 | | blob | history |
diff --combined builtin-grep.c
index af6c6fe8a7ed677de84cdbd828e8daae0a6bb12d,63dc31c45c309c7a2a67977e5631cb5334b32ecf..c7d74fbb7fe26840d4084ad3fef2c8fd4674df6e
--- 1/builtin-grep.c
--- 2/builtin-grep.c
+++ b/builtin-grep.c
error("'%s': %s", filename, strerror(errno));
return 0;
}
- if (!st.st_size)
- return 0; /* empty file -- no grep hit */
if (!S_ISREG(st.st_mode))
return 0;
sz = xsize_t(st.st_size);
return 0;
}
close(i);
+ data[sz] = 0;
if (opt->relative && opt->prefix_length)
filename = quote_path_relative(filename, -1, &buf, opt->prefix);
i = grep_buffer(opt, filename, data, sz);
if (opt->color_external && strlen(opt->color_external) > 0)
push_arg(opt->color_external);
+ } else {
+ unsetenv("GREP_COLOR");
+ unsetenv("GREP_COLORS");
}
+ unsetenv("GREP_OPTIONS");
hit = 0;
argc = nr;
OPT_END()
};
+ /*
+ * 'git grep -h', unlike 'git grep -h <pattern>', is a request
+ * to show usage information and exit.
+ */
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage_with_options(grep_usage, options);
+
memset(&opt, 0, sizeof(opt));
opt.prefix = prefix;
opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;