From ec76125f9d761c08e28f2c55a57cf350ddae5fd9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 7 Feb 2010 19:58:28 +0100 Subject: [PATCH] Unify code paths of threaded greps There were two awfully similar code paths ending the threaded grep. It is better to avoid duplicated code, though. This change might very well prevent a race, where the grep patterns were free()d before waiting that all threads finished. Signed-off-by: Johannes Schindelin --- builtin/grep.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index d0a73da07a..4f30a9af2d 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -590,7 +590,6 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) if (hit && opt->status_only) break; } - free_grep_patterns(opt); return hit; } @@ -1016,28 +1015,24 @@ int cmd_grep(int argc, const char **argv, const char *prefix) } if (!list.nr) { - int hit; if (!cached) setup_work_tree(); hit = grep_cache(&opt, paths, cached); - if (use_threads) - hit |= wait_all(); - return !hit; } - - if (cached) + else if (cached) die("both --cached and trees are given."); - - for (i = 0; i < list.nr; i++) { - struct object *real_obj; - real_obj = deref_tag(list.objects[i].item, NULL, 0); - if (grep_object(&opt, paths, real_obj, list.objects[i].name)) { - hit = 1; - if (opt.status_only) - break; + else + for (i = 0; i < list.nr; i++) { + struct object *real_obj; + real_obj = deref_tag(list.objects[i].item, NULL, 0); + if (grep_object(&opt, paths, real_obj, + list.objects[i].name)) { + hit = 1; + if (opt.status_only) + break; + } } - } if (use_threads) hit |= wait_all();