@matheusbsbs / matheus-bagliano / commits / 685359cf2d
Fork 0

Unify code paths of threaded greps

There were three 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 <johannes.schindelin@gmx.de> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 12, 2010 at 11:32 UTC 685359cf2d1996aed2f1b1e2857528819d27105d
1 file changed +5 -17
builtin/grep.c
+5 -17
@@ -590,7 +590,6 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
590 if (hit && opt->status_only)
591 break;
592 }
593 - free_grep_patterns(opt);
593 return hit;
594 }
595
@@ -708,7 +707,6 @@ static int grep_directory(struct grep_opt *opt, const char **paths)
707 if (hit && opt->status_only)
708 break;
709 }
711 - free_grep_patterns(opt);
710 return hit;
711 }
712
@@ -1019,32 +1017,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1017 }
1018
1019 if (!use_index) {
1022 - int hit;
1020 if (cached)
1021 die("--cached cannot be used with --no-index.");
1022 if (list.nr)
1023 die("--no-index cannot be used with revs.");
1024 hit = grep_directory(&opt, paths);
1028 - if (use_threads)
1029 - hit |= wait_all();
1030 - return !hit;
1031 - }
1032 -
1033 - if (!list.nr) {
1034 - int hit;
1025 + } else if (!list.nr) {
1026 if (!cached)
1027 setup_work_tree();
1028
1029 hit = grep_cache(&opt, paths, cached);
1039 - if (use_threads)
1040 - hit |= wait_all();
1041 - return !hit;
1030 + } else {
1031 + if (cached)
1032 + die("both --cached and trees are given.");
1033 + hit = grep_objects(&opt, paths, &list);
1034 }
1035
1044 - if (cached)
1045 - die("both --cached and trees are given.");
1046 - hit = grep_objects(&opt, paths, &list);
1047 -
1036 if (use_threads)
1037 hit |= wait_all();
1038 free_grep_patterns(&opt);