Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Documentation/RelNotes/2.56.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ Performance, Internal Implementation, Development Support etc.
analysis of different compression settings by comparing the
resulting pack sizes.

* The global variable 'fetch_if_missing' has been moved to a member in
'struct repository', continuing the libification process and
allowing per-repository control (such as for submodules).


Fixes since v2.55
-----------------
Expand Down Expand Up @@ -746,3 +750,4 @@ Fixes since v2.55

* Other code cleanup, docfix, build fix, etc.
(merge 026636128f ss/submittingpatches-typofix later to maint).
(merge d2af22cc21 jc/rerere-doc-typofix later to maint).
2 changes: 1 addition & 1 deletion Documentation/technical/partial-clone.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ and prefetch those objects in bulk.
- `repack` in GC has been updated to not touch promisor packfiles at all,
and to only repack other objects.

- The global variable "fetch_if_missing" is used to control whether an
- The per-repository flag "fetch_if_missing" is used to control whether an
object lookup will attempt to dynamically fetch a missing object or
report an error.
+
Expand Down
2 changes: 1 addition & 1 deletion Documentation/technical/rerere.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Sorting hunks
~~~~~~~~~~~~~

As before, let's imagine that a common ancestor had a file with line A
its early part, and line X in its late part. And then four branches
in its early part, and line X in its late part. And then four branches
are forked that do these things:

- AB: changes A to B
Expand Down
6 changes: 3 additions & 3 deletions builtin/fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
int cmd_fetch_pack(int argc,
const char **argv,
const char *prefix UNUSED,
struct repository *repo UNUSED)
struct repository *repo)
{
int i, ret;
struct ref *fetched_refs = NULL, *remote_refs = NULL;
Expand All @@ -67,8 +67,6 @@ int cmd_fetch_pack(int argc,
struct packet_reader reader;
enum protocol_version version;

fetch_if_missing = 0;

packet_trace_identity("fetch-pack");

memset(&args, 0, sizeof(args));
Expand All @@ -77,6 +75,8 @@ int cmd_fetch_pack(int argc,

show_usage_if_asked(argc, argv, fetch_pack_usage);

repo->fetch_if_missing = 0;

for (i = 1; i < argc && *argv[i] == '-'; i++) {
const char *arg = argv[i];

Expand Down
6 changes: 3 additions & 3 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,15 @@ int cmd_fsck(int argc,
.ref = NULL
};

/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;

errors_found = 0;
disable_replace_refs();
save_commit_buffer = 0;

argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);

/* fsck knows how to handle missing promisor objects */
repo->fetch_if_missing = 0;

fsck_options_init(&fsck_walk_options, repo, FSCK_OPTIONS_DEFAULT);
fsck_walk_options.walk = mark_object;

Expand Down
8 changes: 4 additions & 4 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ static void repack_local_links(void)
int cmd_index_pack(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
const char *curr_index;
Expand All @@ -1903,15 +1903,15 @@ int cmd_index_pack(int argc,
int report_end_of_input = 0;
int hash_algo = 0;

show_usage_if_asked(argc, argv, index_pack_usage);

/*
* index-pack never needs to fetch missing objects except when
* REF_DELTA bases are missing (which are explicitly handled). It only
* accesses the repo to do hash collision checks and to check which
* REF_DELTA bases need to be fetched.
*/
fetch_if_missing = 0;

show_usage_if_asked(argc, argv, index_pack_usage);
(repo ? repo : the_repository)->fetch_if_missing = 0;

disable_replace_refs();

Expand Down
32 changes: 18 additions & 14 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -4090,19 +4090,20 @@ static void stdin_packs_read_input(struct rev_info *revs,

static void add_unreachable_loose_objects(struct rev_info *revs);

static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
static void read_stdin_packs(struct repository *repo,
enum stdin_packs_mode mode, int rev_list_unpacked)
{
int prev_fetch_if_missing = fetch_if_missing;
int prev_fetch_if_missing = repo->fetch_if_missing;
struct rev_info revs;

/*
* The revision walk may hit objects that are promised, only. As the
* walk is best-effort though we don't want to perform backfill fetches
* for them.
*/
fetch_if_missing = 0;
repo->fetch_if_missing = 0;

repo_init_revisions(the_repository, &revs, NULL);
repo_init_revisions(repo, &revs, NULL);
/*
* Use a revision walk to fill in the namehash of objects in the include
* packs. To save time, we'll avoid traversing through objects that are
Expand Down Expand Up @@ -4148,7 +4149,7 @@ static void read_stdin_packs(enum stdin_packs_mode mode, int rev_list_unpacked)
trace2_data_intmax("pack-objects", the_repository, "stdin_packs_hints",
stdin_packs_hints_nr);

fetch_if_missing = prev_fetch_if_missing;
repo->fetch_if_missing = prev_fetch_if_missing;
}

static void add_cruft_object_entry(const struct object_id *oid, enum object_type type,
Expand Down Expand Up @@ -4458,9 +4459,11 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
show_object(obj, name, data);
}

static int option_parse_missing_action(const struct option *opt UNUSED,
static int option_parse_missing_action(const struct option *opt,
const char *arg, int unset)
{
struct repository *repo = opt->value;

assert(arg);
assert(!unset);

Expand All @@ -4472,14 +4475,14 @@ static int option_parse_missing_action(const struct option *opt UNUSED,

if (!strcmp(arg, "allow-any")) {
arg_missing_action = MA_ALLOW_ANY;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
fn_show_object = show_object__ma_allow_any;
return 0;
}

if (!strcmp(arg, "allow-promisor")) {
arg_missing_action = MA_ALLOW_PROMISOR;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
fn_show_object = show_object__ma_allow_promisor;
return 0;
}
Expand Down Expand Up @@ -5120,7 +5123,7 @@ static int parse_stdin_packs_mode(const struct option *opt, const char *arg,
int cmd_pack_objects(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
int use_internal_rev_list = 0;
int all_progress_implied = 0;
Expand Down Expand Up @@ -5227,7 +5230,7 @@ int cmd_pack_objects(int argc,
N_("write a bitmap index if possible"),
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
OPT_CALLBACK_F(0, "missing", NULL, N_("action"),
OPT_CALLBACK_F(0, "missing", repo, N_("action"),
N_("handling for missing objects"), PARSE_OPT_NONEG,
option_parse_missing_action),
OPT_BOOL(0, "exclude-promisor-objects", &exclude_promisor_objects,
Expand Down Expand Up @@ -5347,7 +5350,7 @@ int cmd_pack_objects(int argc,
exclude_promisor_objects_best_effort,
"--exclude-promisor-objects-best-effort");
if (exclude_promisor_objects) {
fetch_if_missing = 0;
repo->fetch_if_missing = 0;

/* --stdin-packs handles promisor objects separately. */
if (!stdin_packs) {
Expand All @@ -5356,8 +5359,9 @@ int cmd_pack_objects(int argc,
}
} else if (exclude_promisor_objects_best_effort) {
use_internal_rev_list = 1;
fetch_if_missing = 0;
option_parse_missing_action(NULL, "allow-any", 0);
arg_missing_action = MA_ALLOW_ANY;
repo->fetch_if_missing = 0;
fn_show_object = show_object__ma_allow_any;
/* revs configured below */
}
if (unpack_unreachable || keep_unreachable || pack_loose_unreachable)
Expand Down Expand Up @@ -5473,7 +5477,7 @@ int cmd_pack_objects(int argc,
progress_state = start_progress(the_repository,
_("Enumerating objects"), 0);
if (stdin_packs) {
read_stdin_packs(stdin_packs, rev_list_unpacked);
read_stdin_packs(repo, stdin_packs, rev_list_unpacked);
} else if (cruft) {
read_cruft_objects();
} else if (!use_internal_rev_list) {
Expand Down
2 changes: 1 addition & 1 deletion builtin/prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int cmd_prune(int argc,
if (show_progress == -1)
show_progress = isatty(2);
if (exclude_promisor_objects) {
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
revs.exclude_promisor_objects = 1;
}

Expand Down
17 changes: 9 additions & 8 deletions builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ static void print_disk_usage(off_t size)
strbuf_release(&sb);
}

static inline int parse_missing_action_value(const char *value)
static inline int parse_missing_action_value(struct repository *repo,
const char *value)
{
if (!strcmp(value, "error")) {
arg_missing_action = MA_ERROR;
Expand All @@ -509,25 +510,25 @@ static inline int parse_missing_action_value(const char *value)

if (!strcmp(value, "allow-any")) {
arg_missing_action = MA_ALLOW_ANY;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
return 1;
}

if (!strcmp(value, "print")) {
arg_missing_action = MA_PRINT;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
return 1;
}

if (!strcmp(value, "print-info")) {
arg_missing_action = MA_PRINT_INFO;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
return 1;
}

if (!strcmp(value, "allow-promisor")) {
arg_missing_action = MA_ALLOW_PROMISOR;
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
return 1;
}

Expand Down Expand Up @@ -692,7 +693,7 @@ static void prepare_maximal_independent(struct rev_info *revs)
int cmd_rev_list(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
struct rev_info revs;
struct rev_list_info info;
Expand Down Expand Up @@ -745,10 +746,10 @@ int cmd_rev_list(int argc,
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "--exclude-promisor-objects")) {
fetch_if_missing = 0;
repo->fetch_if_missing = 0;
revs.exclude_promisor_objects = 1;
} else if (skip_prefix(arg, "--missing=", &arg)) {
parse_missing_action_value(arg);
parse_missing_action_value(repo, arg);
} else if (!strcmp(arg, "-z")) {
line_term = '\0';
info_term = '\0';
Expand Down
2 changes: 1 addition & 1 deletion common-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void setup_environment(void)
update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base);

if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
fetch_if_missing = 0;
the_repository->fetch_if_missing = 0;
}

void init_git(const char **argv)
Expand Down
2 changes: 1 addition & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-lazy-fetch")) {
fetch_if_missing = 0;
the_repository->fetch_if_missing = 0;
setenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 1);
if (envchanged)
*envchanged = 1;
Expand Down
2 changes: 1 addition & 1 deletion midx-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ static void find_commits_for_midx_bitmap(struct commit_stack *commits,
* complain later that we don't have reachability closure (and fail
* appropriately).
*/
fetch_if_missing = 0;
ctx->repo->fetch_if_missing = 0;
revs.exclude_promisor_objects = 1;

if (prepare_revision_walk(&revs))
Expand Down
4 changes: 1 addition & 3 deletions odb.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ void disable_obj_read_lock(void)
pthread_mutex_destroy(&obj_read_mutex);
}

int fetch_if_missing = 1;

static int register_all_submodule_sources(struct object_database *odb)
{
int ret = odb->submodule_source_paths.nr;
Expand Down Expand Up @@ -627,7 +625,7 @@ static enum odb_read_status do_oid_object_info_extended(struct object_database *
continue;

/* Check if it is a missing object */
if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
if (odb->repo->fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
promisor_remote_get_direct(odb->repo, real, 1);
Expand Down
8 changes: 0 additions & 8 deletions odb.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ struct repository;
struct strbuf;
struct strvec;

/*
* Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
*/
extern int fetch_if_missing;

/*
* Compute the exact path an alternate is at and returns it. In case of
* error NULL is returned and the human readable error is added to `err`
Expand Down
1 change: 1 addition & 0 deletions repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void initialize_repository(struct repository *repo)
index_state_init(repo->index, repo);
repo->check_deprecated_config = true;
repo->bare_cfg = -1;
repo->fetch_if_missing = 1;
repo_config_values_init(&repo->config_values_private_);

/*
Expand Down
6 changes: 6 additions & 0 deletions repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ struct repository {
/* True if commit-graph has been disabled within this process. */
int commit_graph_disabled;

/*
* Controls whether the repository should lazily fetch missing
* objects from promisor remotes. Defaults to 1.
*/
int fetch_if_missing;

/*
* Lazily-populated cache mapping hook event names to configured hooks.
* NULL until first hook use.
Expand Down
2 changes: 1 addition & 1 deletion revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->ignore_missing = 1;
} else if (opt && opt->allow_exclude_promisor_objects &&
!strcmp(arg, "--exclude-promisor-objects")) {
if (fetch_if_missing)
if (revs->repo->fetch_if_missing)
BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0");
revs->exclude_promisor_objects = 1;
} else {
Expand Down