From: Junio C Hamano Date: Wed, 17 Feb 2010 22:55:15 +0000 (-0800) Subject: Merge branch 'jk/grep-double-dash' into maint X-Git-Tag: v1.7.0.1~17 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/031f82f75124dc96e3bebf8fa0b15eddf5544012?ds=inline;hp=-c Merge branch 'jk/grep-double-dash' into maint * jk/grep-double-dash: accept "git grep -- pattern" --- 031f82f75124dc96e3bebf8fa0b15eddf5544012 diff --combined builtin-grep.c index 362122c432,63d4b95b0d..26979577d3 --- a/builtin-grep.c +++ b/builtin-grep.c @@@ -408,25 -408,15 +408,25 @@@ static int pathspec_matches(const char return 0; } +static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) +{ + void *data; + + if (use_threads) { + read_sha1_lock(); + data = read_sha1_file(sha1, type, size); + read_sha1_unlock(); + } else { + data = read_sha1_file(sha1, type, size); + } + return data; +} + static void *load_sha1(const unsigned char *sha1, unsigned long *size, const char *name) { enum object_type type; - char *data; - - read_sha1_lock(); - data = read_sha1_file(sha1, &type, size); - read_sha1_unlock(); + void *data = lock_and_read_sha1_file(sha1, &type, size); if (!data) error("'%s': unable to read %s", name, sha1_to_hex(sha1)); @@@ -615,7 -605,10 +615,7 @@@ static int grep_tree(struct grep_opt *o void *data; unsigned long size; - read_sha1_lock(); - data = read_sha1_file(entry.sha1, &type, &size); - read_sha1_unlock(); - + data = lock_and_read_sha1_file(entry.sha1, &type, &size); if (!data) die("unable to read tree (%s)", sha1_to_hex(entry.sha1)); @@@ -868,6 -861,16 +868,16 @@@ int cmd_grep(int argc, const char **arg PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); + /* + * skip a -- separator; we know it cannot be + * separating revisions from pathnames if + * we haven't even had any patterns yet + */ + if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { + argv++; + argc--; + } + /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0,