Skip submodule checkout pass if no submodules Skip the third pass of checkout (where submodules are checked out) if the earlier passes found no submodules to be checked out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/src/checkout.c b/src/checkout.c
index 6f5cfff..74ac379 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -30,6 +30,7 @@ struct checkout_diff_data
git_indexer_stats *stats;
git_repository *owner;
bool can_symlink;
+ bool found_submodules;
bool create_submodules;
int error;
};
@@ -242,6 +243,8 @@ static int checkout_create_the_new(
if (do_checkout) {
bool is_submodule = S_ISGITLINK(delta->old_file.mode);
+ data->found_submodules = true;
+
if (!is_submodule && !data->create_submodules)
error = checkout_blob(data, &delta->old_file);
@@ -339,7 +342,8 @@ int git_checkout_index(
stats = &dummy_stats;
stats->processed = 0;
- stats->total = (unsigned int)git_diff_num_deltas(diff) * 3 /* # passes */;
+ /* total based on 3 passes, but it might be 2 if no submodules */
+ stats->total = (unsigned int)git_diff_num_deltas(diff) * 3;
memset(&data, 0, sizeof(data));
@@ -365,7 +369,8 @@ int git_checkout_index(
if (!(error = git_diff_foreach(
diff, &data, checkout_remove_the_old, NULL, NULL)) &&
!(error = git_diff_foreach(
- diff, &data, checkout_create_the_new, NULL, NULL)))
+ diff, &data, checkout_create_the_new, NULL, NULL)) &&
+ data.found_submodules)
{
data.create_submodules = true;
error = git_diff_foreach(