Code

Merge branch 'jm/maint-1.6.5-grep-NUL-terminate' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Jan 2010 01:03:34 +0000 (17:03 -0800)
committerJunio 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

1  2 
builtin-grep.c

diff --combined builtin-grep.c
index af6c6fe8a7ed677de84cdbd828e8daae0a6bb12d,63dc31c45c309c7a2a67977e5631cb5334b32ecf..c7d74fbb7fe26840d4084ad3fef2c8fd4674df6e
@@@ -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);
                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 <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;