grep: move thread initialization a little lower
Originally, we set up the threads for grep before parsing the non-option arguments. In 53b8d931b (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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 14, 2017 at 01:02 UTC
a0fe2b0d2329d38a08c03427917b21be818bec1f
1 file changed
+14
-14
builtin/grep.c
+14
-14
@@ -1169,6 +1169,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1169
break;
1170
}
1171
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
+
1186
#ifndef NO_PTHREADS
1187
if (list.nr || cached || show_in_pager)
1188
num_threads = 0;
@@ -1190,20 +1204,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1204
}
1205
#endif
1206
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
-
1207
if (recurse_submodules) {
1208
gitmodules_config();
1209
compile_submodule_options(&opt, &pathspec, cached, untracked,