Merge branch 'ds/sparse-index-protections'
Builds on top of the sparse-index infrastructure to mark operations that are not ready to mark with the sparse index, causing them to fall back on fully-populated index that they always have worked with. * ds/sparse-index-protections: (47 commits) name-hash: use expand_to_path() sparse-index: expand_to_path() name-hash: don't add directories to name_hash revision: ensure full index resolve-undo: ensure full index read-cache: ensure full index pathspec: ensure full index merge-recursive: ensure full index entry: ensure full index dir: ensure full index update-index: ensure full index stash: ensure full index rm: ensure full index merge-index: ensure full index ls-files: ensure full index grep: ensure full index fsck: ensure full index difftool: ensure full index commit: ensure full index checkout: ensure full index ...
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include "unpack-trees.h"
|
||||
#include "wt-status.h"
|
||||
#include "quote.h"
|
||||
#include "sparse-index.h"
|
||||
|
||||
static const char *empty_base = "";
|
||||
|
||||
@ -110,6 +111,8 @@ static int update_working_directory(struct pattern_list *pl)
|
||||
if (is_index_unborn(r->index))
|
||||
return UPDATE_SPARSITY_SUCCESS;
|
||||
|
||||
r->index->sparse_checkout_patterns = pl;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.verbose_update = isatty(2);
|
||||
o.update = 1;
|
||||
@ -138,6 +141,7 @@ static int update_working_directory(struct pattern_list *pl)
|
||||
else
|
||||
rollback_lock_file(&lock_file);
|
||||
|
||||
r->index->sparse_checkout_patterns = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -276,16 +280,20 @@ static int set_config(enum sparse_checkout_mode mode)
|
||||
"core.sparseCheckoutCone",
|
||||
mode == MODE_CONE_PATTERNS ? "true" : NULL);
|
||||
|
||||
if (mode == MODE_NO_PATTERNS)
|
||||
set_sparse_index_config(the_repository, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char const * const builtin_sparse_checkout_init_usage[] = {
|
||||
N_("git sparse-checkout init [--cone]"),
|
||||
N_("git sparse-checkout init [--cone] [--[no-]sparse-index]"),
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct sparse_checkout_init_opts {
|
||||
int cone_mode;
|
||||
int sparse_index;
|
||||
} init_opts;
|
||||
|
||||
static int sparse_checkout_init(int argc, const char **argv)
|
||||
@ -300,11 +308,15 @@ static int sparse_checkout_init(int argc, const char **argv)
|
||||
static struct option builtin_sparse_checkout_init_options[] = {
|
||||
OPT_BOOL(0, "cone", &init_opts.cone_mode,
|
||||
N_("initialize the sparse-checkout in cone mode")),
|
||||
OPT_BOOL(0, "sparse-index", &init_opts.sparse_index,
|
||||
N_("toggle the use of a sparse index")),
|
||||
OPT_END(),
|
||||
};
|
||||
|
||||
repo_read_index(the_repository);
|
||||
|
||||
init_opts.sparse_index = -1;
|
||||
|
||||
argc = parse_options(argc, argv, NULL,
|
||||
builtin_sparse_checkout_init_options,
|
||||
builtin_sparse_checkout_init_usage, 0);
|
||||
@ -323,10 +335,20 @@ static int sparse_checkout_init(int argc, const char **argv)
|
||||
sparse_filename = get_sparse_checkout_filename();
|
||||
res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
|
||||
|
||||
if (init_opts.sparse_index >= 0) {
|
||||
if (set_sparse_index_config(the_repository, init_opts.sparse_index) < 0)
|
||||
die(_("failed to modify sparse-index config"));
|
||||
|
||||
/* force an index rewrite */
|
||||
repo_read_index(the_repository);
|
||||
the_repository->index->updated_workdir = 1;
|
||||
}
|
||||
|
||||
core_apply_sparse_checkout = 1;
|
||||
|
||||
/* If we already have a sparse-checkout file, use it. */
|
||||
if (res >= 0) {
|
||||
free(sparse_filename);
|
||||
core_apply_sparse_checkout = 1;
|
||||
return update_working_directory(NULL);
|
||||
}
|
||||
|
||||
@ -348,6 +370,7 @@ static int sparse_checkout_init(int argc, const char **argv)
|
||||
add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
|
||||
strbuf_addstr(&pattern, "!/*/");
|
||||
add_pattern(strbuf_detach(&pattern, NULL), empty_base, 0, &pl, 0);
|
||||
pl.use_cone_patterns = init_opts.cone_mode;
|
||||
|
||||
return write_patterns_and_update(&pl);
|
||||
}
|
||||
@ -517,19 +540,18 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
|
||||
{
|
||||
int result;
|
||||
int changed_config = 0;
|
||||
struct pattern_list pl;
|
||||
memset(&pl, 0, sizeof(pl));
|
||||
struct pattern_list *pl = xcalloc(1, sizeof(*pl));
|
||||
|
||||
switch (m) {
|
||||
case ADD:
|
||||
if (core_sparse_checkout_cone)
|
||||
add_patterns_cone_mode(argc, argv, &pl);
|
||||
add_patterns_cone_mode(argc, argv, pl);
|
||||
else
|
||||
add_patterns_literal(argc, argv, &pl);
|
||||
add_patterns_literal(argc, argv, pl);
|
||||
break;
|
||||
|
||||
case REPLACE:
|
||||
add_patterns_from_input(&pl, argc, argv);
|
||||
add_patterns_from_input(pl, argc, argv);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -539,12 +561,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
|
||||
changed_config = 1;
|
||||
}
|
||||
|
||||
result = write_patterns_and_update(&pl);
|
||||
result = write_patterns_and_update(pl);
|
||||
|
||||
if (result && changed_config)
|
||||
set_config(MODE_NO_PATTERNS);
|
||||
|
||||
clear_pattern_list(&pl);
|
||||
clear_pattern_list(pl);
|
||||
free(pl);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -614,6 +637,9 @@ static int sparse_checkout_disable(int argc, const char **argv)
|
||||
strbuf_addstr(&match_all, "/*");
|
||||
add_pattern(strbuf_detach(&match_all, NULL), empty_base, 0, &pl, 0);
|
||||
|
||||
prepare_repo_settings(the_repository);
|
||||
the_repository->settings.sparse_index = 0;
|
||||
|
||||
if (update_working_directory(&pl))
|
||||
die(_("error while refreshing working directory"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user