Re: [PATCH v2 2/3] replace-objects: create wrapper around setting
From: René Scharfe <hidden>
Date: 2023-06-03 06:22:52
Am 02.06.23 um 16:29 schrieb Derrick Stolee via GitGitGadget:
quoted hunk ↗ jump to hunk
diff --git a/replace-object.c b/replace-object.c index ceec81c940c..cf91c3ba456 100644 --- a/replace-object.c +++ b/replace-object.c@@ -85,7 +85,14 @@ const struct object_id *do_lookup_replace_object(struct repository *r, die(_("replace depth too high for object %s"), oid_to_hex(oid)); } +static int read_replace_refs = 1; +
This breaks compilation:
replace-object.c:88:12: error: static declaration of 'read_replace_refs' follows non-static declaration
static int read_replace_refs = 1;
^
./replace-object.h:14:12: note: previous declaration is here
extern int read_replace_refs;
^
And this variable is still referenced in two more places outside this
file, which won't work now that it has become static (file-scoped):
$ git grep read_replace_refs
builtin/commit-graph.c:extern int read_replace_refs;
config.c: read_replace_refs = git_config_bool(var, value);
replace-object.c: * references, regardless of the value of read_replace_refs.
replace-object.c:static int read_replace_refs = 1;
replace-object.c: read_replace_refs = 0;
replace-object.c: return read_replace_refs;
replace-object.h:extern int read_replace_refs;
Perhaps postpone adding "static" to patch 3?
quoted hunk ↗ jump to hunk
void disable_replace_refs(void) { read_replace_refs = 0; } + +int replace_refs_enabled(struct repository *r) +{ + return read_replace_refs; +}diff --git a/replace-object.h b/replace-object.h index 7786d4152b0..b141075023e 100644 --- a/replace-object.h +++ b/replace-object.h@@ -27,6 +27,19 @@ void prepare_replace_object(struct repository *r); const struct object_id *do_lookup_replace_object(struct repository *r, const struct object_id *oid); + +/* + * Some commands disable replace-refs unconditionally, and otherwise each + * repository could alter the core.useReplaceRefs config value. + * + * Return 1 if and only if all of the following are true: + * + * a. disable_replace_refs() has not been called. + * b. GIT_NO_REPLACE_OBJECTS is unset or zero. + * c. the given repository does not have core.useReplaceRefs=false. + */ +int replace_refs_enabled(struct repository *r); + /* * If object sha1 should be replaced, return the replacement object's * name (replaced recursively, if necessary). The return value is@@ -41,7 +54,7 @@ const struct object_id *do_lookup_replace_object(struct repository *r, static inline const struct object_id *lookup_replace_object(struct repository *r, const struct object_id *oid) { - if (!read_replace_refs || + if (!replace_refs_enabled(r) || (r->objects->replace_map_initialized && r->objects->replace_map->map.tablesize == 0)) return oid;