X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=builtin-grep.c;h=552ef1face1e25c11d5f114c8d5c1265c6c3ae9b;hb=0901d5a2ef80996cf64c8afeaec765e1bc09f795;hp=9bd467c9b90d1c58a59e27fbc6673cb68d855c72;hpb=b10b9184afc9e62140d307dcf2f5d7e625f78c79;p=git.git diff --git a/builtin-grep.c b/builtin-grep.c index 9bd467c9b..552ef1fac 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -205,6 +205,8 @@ static void *run(void *arg) work_done(w); } + free_grep_patterns(arg); + free(arg); return (void*) (intptr_t) hit; } @@ -407,15 +409,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth) 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)); @@ -604,10 +616,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths, 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)); @@ -887,6 +896,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix) /* die the same way as if we did it at the beginning */ setup_git_directory(); + /* + * 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,