Skip to content

Commit

Permalink
Unify code paths of threaded greps
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho authored and gitster committed Jun 13, 2010
1 parent 30d00c3 commit 685359c
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -708,7 +707,6 @@ static int grep_directory(struct grep_opt *opt, const char **paths)
if (hit && opt->status_only)
break;
}
free_grep_patterns(opt);
return hit;
}

Expand Down Expand Up @@ -1019,32 +1017,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
}

if (!use_index) {
int hit;
if (cached)
die("--cached cannot be used with --no-index.");
if (list.nr)
die("--no-index cannot be used with revs.");
hit = grep_directory(&opt, paths);
if (use_threads)
hit |= wait_all();
return !hit;
}

if (!list.nr) {
int hit;
} else if (!list.nr) {
if (!cached)
setup_work_tree();

hit = grep_cache(&opt, paths, cached);
if (use_threads)
hit |= wait_all();
return !hit;
} else {
if (cached)
die("both --cached and trees are given.");
hit = grep_objects(&opt, paths, &list);
}

if (cached)
die("both --cached and trees are given.");
hit = grep_objects(&opt, paths, &list);

if (use_threads)
hit |= wait_all();
free_grep_patterns(&opt);
Expand Down

0 comments on commit 685359c

Please sign in to comment.