git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/7] rerere: stop using `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 23, 2026, 12:50 UTC
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 <ps@pks.im>
---
 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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 6 of 10 in “rerere: remove global state”
  1. 0/7 rerere: remove global statePatrick Steinhardt, Oct 23, 2026
  2. 1/7 rerere: stop using `the_repository` in `rerere_path()`Patrick Steinhardt, Oct 23, 2026
  3. 2/7 rerere: stop using `the_repository` in internal helpersPatrick Steinhardt, Oct 23, 2026
  4. 3/7 rerere: remove redundant calls to `repo_config()`Patrick Steinhardt, Oct 23, 2026
  5. 4/7 rerere: cache result of `is_rerere_enabled()`Patrick Steinhardt, Oct 23, 2026
  6. 5/7 rerere: stop using `the_repository`Patrick Steinhardt, Oct 23, 2026
  7. 6/7 rerere: bundle global state into a structPatrick Steinhardt, Oct 23, 2026
  8. 7/7 rerere: get rid of global rerere cache statePatrick Steinhardt, Oct 23, 2026
  9. Junio C HamanoOct 23, 2026
  10. Patrick SteinhardtOct 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.