Skip to content

Commit a0fe2b0

Browse files
peffgitster
authored andcommitted
grep: move thread initialization a little lower
Originally, we set up the threads for grep before parsing the non-option arguments. In 53b8d93 (grep: disable threading in non-worktree case, 2011-12-12), the thread code got bumped lower in the function because it now needed to know whether we got any revision arguments. That put a big block of code in between the parsing of revs and the parsing of pathspecs, both of which share some loop variables. That makes it harder to read the code than the original, where the shared loops were right next to each other. Let's bump the thread initialization until after all of the parsing is done. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5588dbf commit a0fe2b0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

builtin/grep.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11691169
break;
11701170
}
11711171

1172+
/* The rest are paths */
1173+
if (!seen_dashdash) {
1174+
int j;
1175+
for (j = i; j < argc; j++)
1176+
verify_filename(prefix, argv[j], j == i);
1177+
}
1178+
1179+
parse_pathspec(&pathspec, 0,
1180+
PATHSPEC_PREFER_CWD |
1181+
(opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0),
1182+
prefix, argv + i);
1183+
pathspec.max_depth = opt.max_depth;
1184+
pathspec.recursive = 1;
1185+
11721186
#ifndef NO_PTHREADS
11731187
if (list.nr || cached || show_in_pager)
11741188
num_threads = 0;
@@ -1190,20 +1204,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11901204
}
11911205
#endif
11921206

1193-
/* The rest are paths */
1194-
if (!seen_dashdash) {
1195-
int j;
1196-
for (j = i; j < argc; j++)
1197-
verify_filename(prefix, argv[j], j == i);
1198-
}
1199-
1200-
parse_pathspec(&pathspec, 0,
1201-
PATHSPEC_PREFER_CWD |
1202-
(opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0),
1203-
prefix, argv + i);
1204-
pathspec.max_depth = opt.max_depth;
1205-
pathspec.recursive = 1;
1206-
12071207
if (recurse_submodules) {
12081208
gitmodules_config();
12091209
compile_submodule_options(&opt, &pathspec, cached, untracked,

0 commit comments

Comments
 (0)