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

[PATCH] loose: don't rely on repository global state

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 9, 2024, 09:58 UTC
Message-ID
<CAOLa=ZRMaw-PAsZ9s0zJ2zp_suMppi=ZrT67B__LU1tWZSvuUQ@mail.gmail.com>

In `loose.c`, we rely on the global variable `the_hash_algo`. As such we have guarded the file with the 'USE_THE_REPOSITORY_VARIABLE' definition. Let's derive the hash algorithm from the available repository variable and remove this guard. This brings us one step closer to removing the global 'the_repository' variable.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 loose.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/loose.c b/loose.c
index 6d6a41b7e5..897ba389da 100644
--- a/loose.c
+++ b/loose.c
@@ -1,10 +1,9 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "hash.h"
 #include "path.h"
 #include "object-store.h"
 #include "hex.h"
+#include "repository.h"
 #include "wrapper.h"
 #include "gettext.h"
 #include "loose.h"
@@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)

 	for (; iter != kh_end(map); iter++) {
 		if (kh_exist(map, iter)) {
-			if (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||
-			    oideq(&kh_key(map, iter), the_hash_algo->empty_blob))
+			if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||
+			    oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))
 				continue;
 			strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)),
oid_to_hex(kh_value(map, iter)));
 			if (write_in_full(fd, buf.buf, buf.len) < 0)
-- 
2.46.2
Next: Junio C Hamano
Message 1 of 4 in “loose: don't rely on repository global state”
  1. loose: don't rely on repository global stateKarthik Nayak, Oct 9, 2024
  2. Junio C HamanoOct 9, 2024
  3. Karthik NayakOct 9, 2024
  4. Patrick SteinhardtOct 10, 2024

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.