aboutsummaryrefslogtreecommitdiff
path: root/builtin/sparse-checkout.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/sparse-checkout.c')
-rw-r--r--builtin/sparse-checkout.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 15d51e60a8..f4aa405da9 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -61,9 +61,10 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
struct pattern_list pl;
char *sparse_filename;
int res;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
setup_work_tree();
- if (!core_apply_sparse_checkout)
+ if (!cfg->apply_sparse_checkout)
die(_("this worktree is not sparse"));
argc = parse_options(argc, argv, prefix,
@@ -91,10 +92,10 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix,
hashmap_for_each_entry(&pl.recursive_hashmap, &iter, pe, ent) {
/* pe->pattern starts with "/", skip it */
- string_list_insert(&sl, pe->pattern + 1);
+ string_list_append(&sl, pe->pattern + 1);
}
- string_list_sort(&sl);
+ string_list_sort_u(&sl, 0);
for (i = 0; i < sl.nr; i++) {
quote_c_style(sl.items[i].string, NULL, stdout, 0);
@@ -289,11 +290,10 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl)
if (!hashmap_contains_parent(&pl->recursive_hashmap,
pe->pattern,
&parent_pattern))
- string_list_insert(&sl, pe->pattern);
+ string_list_append(&sl, pe->pattern);
}
- string_list_sort(&sl);
- string_list_remove_duplicates(&sl, 0);
+ string_list_sort_u(&sl, 0);
fprintf(fp, "/*\n!/*/\n");
@@ -311,13 +311,12 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl)
if (!hashmap_contains_parent(&pl->recursive_hashmap,
pe->pattern,
&parent_pattern))
- string_list_insert(&sl, pe->pattern);
+ string_list_append(&sl, pe->pattern);
}
strbuf_release(&parent_pattern);
- string_list_sort(&sl);
- string_list_remove_duplicates(&sl, 0);
+ string_list_sort_u(&sl, 0);
for (i = 0; i < sl.nr; i++) {
char *pattern = escaped_pattern(sl.items[i].string);
@@ -399,12 +398,14 @@ static int set_config(struct repository *repo,
}
static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
+ struct repo_config_values *cfg = repo_config_values(the_repository);
+
/* If not specified, use previous definition of cone mode */
- if (*cone_mode == -1 && core_apply_sparse_checkout)
+ if (*cone_mode == -1 && cfg->apply_sparse_checkout)
*cone_mode = core_sparse_checkout_cone;
/* Set cone/non-cone mode appropriately */
- core_apply_sparse_checkout = 1;
+ cfg->apply_sparse_checkout = 1;
if (*cone_mode == 1 || *cone_mode == -1) {
core_sparse_checkout_cone = 1;
return MODE_CONE_PATTERNS;
@@ -416,9 +417,10 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) {
static int update_modes(struct repository *repo, int *cone_mode, int *sparse_index)
{
int mode, record_mode;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
/* Determine if we need to record the mode; ensure sparse checkout on */
- record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
+ record_mode = (*cone_mode != -1) || !cfg->apply_sparse_checkout;
mode = update_cone_mode(cone_mode);
if (record_mode && set_config(repo, mode))
@@ -684,6 +686,7 @@ static int modify_pattern_list(struct repository *repo,
int result;
int changed_config = 0;
struct pattern_list *pl = xcalloc(1, sizeof(*pl));
+ struct repo_config_values *cfg = repo_config_values(the_repository);
switch (m) {
case ADD:
@@ -699,9 +702,9 @@ static int modify_pattern_list(struct repository *repo,
break;
}
- if (!core_apply_sparse_checkout) {
+ if (!cfg->apply_sparse_checkout) {
set_config(repo, MODE_ALL_PATTERNS);
- core_apply_sparse_checkout = 1;
+ cfg->apply_sparse_checkout = 1;
changed_config = 1;
}
@@ -796,9 +799,10 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix,
};
struct strvec patterns = STRVEC_INIT;
int ret;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
setup_work_tree();
- if (!core_apply_sparse_checkout)
+ if (!cfg->apply_sparse_checkout)
die(_("no sparse-checkout to add to"));
repo_read_index(repo);
@@ -905,9 +909,10 @@ static int sparse_checkout_reapply(int argc, const char **argv,
N_("toggle the use of a sparse index")),
OPT_END(),
};
+ struct repo_config_values *cfg = repo_config_values(the_repository);
setup_work_tree();
- if (!core_apply_sparse_checkout)
+ if (!cfg->apply_sparse_checkout)
die(_("must be in a sparse-checkout to reapply sparsity patterns"));
reapply_opts.cone_mode = -1;
@@ -960,6 +965,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
size_t worktree_len;
int force = 0, dry_run = 0, verbose = 0;
int require_force = 1;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
struct option builtin_sparse_checkout_clean_options[] = {
OPT__DRY_RUN(&dry_run, N_("dry run")),
@@ -969,7 +975,7 @@ static int sparse_checkout_clean(int argc, const char **argv,
};
setup_work_tree();
- if (!core_apply_sparse_checkout)
+ if (!cfg->apply_sparse_checkout)
die(_("must be in a sparse-checkout to clean directories"));
if (!core_sparse_checkout_cone)
die(_("must be in a cone-mode sparse-checkout to clean directories"));
@@ -1033,9 +1039,10 @@ static int sparse_checkout_disable(int argc, const char **argv,
OPT_END(),
};
struct pattern_list pl;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
/*
- * We do not exit early if !core_apply_sparse_checkout; due to the
+ * We do not exit early if !repo->config_values.apply_sparse_checkout; due to the
* ability for users to manually muck things up between
* direct editing of .git/info/sparse-checkout
* running read-tree -m u HEAD or update-index --skip-worktree
@@ -1061,7 +1068,7 @@ static int sparse_checkout_disable(int argc, const char **argv,
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;
+ cfg->apply_sparse_checkout = 1;
add_pattern("/*", empty_base, 0, &pl, 0);