From f46fcc176a246cde86587b42752c4098ebb1c109 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 8e928e2170..b2ac407ea8 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; } @@ -1012,28 +1011,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();