Skip to content

Commit 685359c

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30d00c3 commit 685359c

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

builtin/grep.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
590590
if (hit && opt->status_only)
591591
break;
592592
}
593-
free_grep_patterns(opt);
594593
return hit;
595594
}
596595

@@ -708,7 +707,6 @@ static int grep_directory(struct grep_opt *opt, const char **paths)
708707
if (hit && opt->status_only)
709708
break;
710709
}
711-
free_grep_patterns(opt);
712710
return hit;
713711
}
714712

@@ -1019,32 +1017,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10191017
}
10201018

10211019
if (!use_index) {
1022-
int hit;
10231020
if (cached)
10241021
die("--cached cannot be used with --no-index.");
10251022
if (list.nr)
10261023
die("--no-index cannot be used with revs.");
10271024
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) {
10351026
if (!cached)
10361027
setup_work_tree();
10371028

10381029
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);
10421034
}
10431035

1044-
if (cached)
1045-
die("both --cached and trees are given.");
1046-
hit = grep_objects(&opt, paths, &list);
1047-
10481036
if (use_threads)
10491037
hit |= wait_all();
10501038
free_grep_patterns(&opt);

0 commit comments

Comments
 (0)