summaryrefslogtreecommitdiff
path: root/builtin/sparse-checkout.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-11-21 22:04:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-11-22 07:11:45 (GMT)
commit99dfa6f9702ee81c44ef9382933e4e391ec5d6ee (patch)
treeebd9b7b6ab450e71366c5415b9b10ad3aea906aa /builtin/sparse-checkout.c
parente091228e17e88b1bc16cb50d5c3aff10dc5119d1 (diff)
downloadgit-99dfa6f9702ee81c44ef9382933e4e391ec5d6ee.zip
git-99dfa6f9702ee81c44ef9382933e4e391ec5d6ee.tar.gz
git-99dfa6f9702ee81c44ef9382933e4e391ec5d6ee.tar.bz2
sparse-checkout: use in-process update for disable subcommand
The 'git sparse-checkout disable' subcommand returns a user to a full working directory. The old process for doing this required updating the sparse-checkout file with the "/*" pattern and then updating the working directory with core.sparseCheckout enabled. Finally, the sparse-checkout file could be removed and the config setting disabled. However, it is valuable to keep a user's sparse-checkout file intact so they can re-enable the sparse-checkout they previously used with 'git sparse-checkout init'. This is now possible with the in-process mechanism for updating the working directory. Reported-by: Szeder Gábor <szeder.dev@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/sparse-checkout.c')
-rw-r--r--builtin/sparse-checkout.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index a5d32e4..a11ea65 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -412,24 +412,23 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
static int sparse_checkout_disable(int argc, const char **argv)
{
- char *sparse_filename;
- FILE *fp;
+ static const char *empty_base = "";
+ struct pattern_list pl;
+ struct strbuf match_all = STRBUF_INIT;
- if (set_config(MODE_ALL_PATTERNS))
- die(_("failed to change config"));
+ memset(&pl, 0, sizeof(pl));
+ hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
+ hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);
+ pl.use_cone_patterns = 0;
+ core_apply_sparse_checkout = 1;
- sparse_filename = get_sparse_checkout_filename();
- fp = xfopen(sparse_filename, "w");
- fprintf(fp, "/*\n");
- fclose(fp);
+ strbuf_addstr(&match_all, "/*");
+ add_pattern(strbuf_detach(&match_all, NULL), empty_base, 0, &pl, 0);
- core_apply_sparse_checkout = 1;
- if (update_working_directory(NULL))
+ if (update_working_directory(&pl))
die(_("error while refreshing working directory"));
- unlink(sparse_filename);
- free(sparse_filename);
-
+ clear_pattern_list(&pl);
return set_config(MODE_NO_PATTERNS);
}