Skip to content

Commit 70b052b

Browse files
matheustavaresgitster
authored andcommitted
checkout-index: add parallel checkout support
Allow checkout-index to use the parallel checkout framework, honoring the checkout.workers configuration. There are two code paths in checkout-index which call `checkout_entry()`, and thus, can make use of parallel checkout: `checkout_file()`, which is used to write paths explicitly given at the command line; and `checkout_all()`, which is used to write all paths in the index, when the `--all` option is given. In both operation modes, checkout-index doesn't abort immediately on a `checkout_entry()` failure. Instead, it tries to check out all remaining paths before exiting with a non-zero exit code. To keep this behavior when parallel checkout is being used, we must allow `run_parallel_checkout()` to try writing the queued entries before we exit, even if we already got an error code from a previous `checkout_entry()` call. However, `checkout_all()` doesn't return on errors, it calls `exit()` with code 128. We could make it call `run_parallel_checkout()` before exiting, but it makes the code easier to follow if we unify the exit path for both checkout-index modes at `cmd_checkout_index()`, and let this function take care of the interactions with the parallel checkout API. So let's do that. With this change, we also have to consider whether we want to keep using 128 as the error code for `git checkout-index --all`, while we use 1 for `git checkout-index <path>` (even when the actual error is the same). Since there is not much value in having code 128 only for `--all`, and there is no mention about it in the docs (so it's unlikely that changing it will break any existing script), let's make both modes exit with code 1 on `checkout_entry()` errors. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6053950 commit 70b052b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

builtin/checkout-index.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "cache-tree.h"
1313
#include "parse-options.h"
1414
#include "entry.h"
15+
#include "parallel-checkout.h"
1516

1617
#define CHECKOUT_ALL 4
1718
static int nul_term_line;
@@ -115,7 +116,7 @@ static int checkout_file(const char *name, const char *prefix)
115116
return -1;
116117
}
117118

118-
static void checkout_all(const char *prefix, int prefix_length)
119+
static int checkout_all(const char *prefix, int prefix_length)
119120
{
120121
int i, errs = 0;
121122
struct cache_entry *last_ce = NULL;
@@ -142,11 +143,7 @@ static void checkout_all(const char *prefix, int prefix_length)
142143
}
143144
if (last_ce && to_tempfile)
144145
write_tempfile_record(last_ce->name, prefix);
145-
if (errs)
146-
/* we have already done our error reporting.
147-
* exit with the same code as die().
148-
*/
149-
exit(128);
146+
return !!errs;
150147
}
151148

152149
static const char * const builtin_checkout_index_usage[] = {
@@ -182,6 +179,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
182179
int force = 0, quiet = 0, not_new = 0;
183180
int index_opt = 0;
184181
int err = 0;
182+
int pc_workers, pc_threshold;
185183
struct option builtin_checkout_index_options[] = {
186184
OPT_BOOL('a', "all", &all,
187185
N_("check out all files in the index")),
@@ -236,6 +234,10 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
236234
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
237235
}
238236

237+
get_parallel_checkout_configs(&pc_workers, &pc_threshold);
238+
if (pc_workers > 1)
239+
init_parallel_checkout();
240+
239241
/* Check out named files first */
240242
for (i = 0; i < argc; i++) {
241243
const char *arg = argv[i];
@@ -275,12 +277,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
275277
strbuf_release(&buf);
276278
}
277279

280+
if (all)
281+
err |= checkout_all(prefix, prefix_length);
282+
283+
if (pc_workers > 1)
284+
err |= run_parallel_checkout(&state, pc_workers, pc_threshold,
285+
NULL, NULL);
286+
278287
if (err)
279288
return 1;
280289

281-
if (all)
282-
checkout_all(prefix, prefix_length);
283-
284290
if (is_lock_file_locked(&lock_file) &&
285291
write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
286292
die("Unable to write new index file");

0 commit comments

Comments
 (0)