From: Patrick Steinhardt Date: Fri, 23 Oct 2026 12:50:22 GMT Subject: [PATCH 5/7] rerere: stop using `the_repository` Message-ID: <20261023-pks-rerere-wo-the-repository-v1-5-b6ac0c2e4b81@pks.im> In-Reply-To: <20261023-pks-rerere-wo-the-repository-v1-0-b6ac0c2e4b81@pks.im> There's only a couple of trivial function calls left that implicitly make us depend on `the_repository`. Refactor those to instead use their variants that allow us to make the dependency explicit. Note that this requires us to make `get_hash_hex_algop()` public. With these changes, "rerere.c" no longer depends on `the_repository`, so drop `USE_THE_REPOSITORY_VARIABLE`. Despite that, we still carry some global state in this file that will tie a specific rerere cache to the first repository used to populate it. This will be fixed in subsequent commits. Signed-off-by: Patrick Steinhardt --- hex.c | 4 ++-- hex.h | 3 +++ rerere.c | 14 +++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hex.c b/hex.c index f02832140d..4b7793bb8a 100644 --- a/hex.c +++ b/hex.c @@ -5,8 +5,8 @@ #include "hex.h" #include "strbuf.h" -static int get_hash_hex_algop(const char *hex, unsigned char *hash, - const struct git_hash_algo *algop) +int get_hash_hex_algop(const char *hex, unsigned char *hash, + const struct git_hash_algo *algop) { for (size_t i = 0; i < algop->rawsz; i++) { int val = hex2chr(hex); diff --git a/hex.h b/hex.h index f15c7e2220..50a0088065 100644 --- a/hex.h +++ b/hex.h @@ -59,6 +59,9 @@ int parse_oid_hex_algop_impl(const char *hex, struct object_id *oid, const char int get_oid_hex_any(const char *hex, struct object_id *oid); int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); +int get_hash_hex_algop(const char *hex, unsigned char *hash, + const struct git_hash_algo *algop); + #ifdef USE_THE_REPOSITORY_VARIABLE /* Like get_oid_hex_algop, but for `the_hash_algo`. */ diff --git a/rerere.c b/rerere.c index 8fa921fc8f..366797ab7e 100644 --- a/rerere.c +++ b/rerere.c @@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" @@ -188,7 +187,7 @@ static struct rerere_id *new_rerere_id_hex(struct repository *r, char *hex) static struct rerere_id *new_rerere_id(struct repository *r, unsigned char *hash) { - return new_rerere_id_hex(r, hash_to_hex(hash)); + return new_rerere_id_hex(r, hash_to_hex_algop(hash, r->hash_algo)); } /* @@ -213,7 +212,8 @@ static void read_rr(struct repository *r, struct string_list *rr) const unsigned hexsz = r->hash_algo->hexsz; /* There has to be the hash, tab, path and then NUL */ - if (buf.len < hexsz + 2 || get_hash_hex(buf.buf, hash)) + if (buf.len < hexsz + 2 || + get_hash_hex_algop(buf.buf, hash, r->hash_algo)) die(_("corrupt MERGE_RR")); if (buf.buf[hexsz] != '.') { @@ -1264,11 +1264,11 @@ static void prune_one(struct repository *r, struct rerere_id *id, } /* Does the basename in "path" look plausibly like an rr-cache entry? */ -static int is_rr_cache_dirname(const char *path) +static int is_rr_cache_dirname(struct repository *r, const char *path) { struct object_id oid; const char *end; - return !parse_oid_hex(path, &oid, &end) && !*end; + return !parse_oid_hex_algop(path, &oid, &end, r->hash_algo) && !*end; } bool rerere_gc_needed(struct repository *r, size_t limit) @@ -1295,7 +1295,7 @@ bool rerere_gc_needed(struct repository *r, size_t limit) * use for estimating the number of loose objects. */ if (!starts_with(e->d_name, "17") || - !is_rr_cache_dirname(e->d_name)) + !is_rr_cache_dirname(r, e->d_name)) continue; id.collection = find_rerere_dir(r, e->d_name); @@ -1345,7 +1345,7 @@ void rerere_gc(struct repository *r, struct string_list *rr, int flags) struct rerere_id id; int now_empty; - if (!is_rr_cache_dirname(e->d_name)) + if (!is_rr_cache_dirname(r, e->d_name)) continue; /* or should we remove e->d_name? */ rr_dir = find_rerere_dir(r, e->d_name); -- 2.56.0.307.g5fe7bd680c.dirty