From: Junio C Hamano Date: Tue, 19 Jan 2010 01:03:34 +0000 (-0800) Subject: Merge branch 'jm/maint-1.6.5-grep-NUL-terminate' into maint X-Git-Tag: v1.6.6.1~8 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7d0dafe3945408aeef9c2e5256ac926976170e54?ds=inline;hp=-c Merge branch 'jm/maint-1.6.5-grep-NUL-terminate' into maint * jm/maint-1.6.5-grep-NUL-terminate: grep: NUL terminate input from a file --- 7d0dafe3945408aeef9c2e5256ac926976170e54 diff --combined builtin-grep.c index af6c6fe8a7,63dc31c45c..c7d74fbb7f --- a/builtin-grep.c +++ b/builtin-grep.c @@@ -191,6 -191,8 +191,6 @@@ static int grep_file(struct grep_opt *o 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); @@@ -205,6 -207,7 +205,7 @@@ 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); @@@ -431,11 -434,7 +432,11 @@@ static int external_grep(struct grep_op 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; @@@ -790,13 -789,6 +791,13 @@@ int cmd_grep(int argc, const char **arg OPT_END() }; + /* + * 'git grep -h', unlike 'git grep -h ', 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;