loose: don't rely on repository global state

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Oct 9, 2024 at 02:58 UTC 432f666aa6d9f69d578d44f8c6d6bdb865152ad5
1 file changed +3 -4
loose.c
+3 -4
@@ -1,10 +1,9 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "git-compat-util.h"
2 #include "hash.h"
3 #include "path.h"
4 #include "object-store.h"
5 #include "hex.h"
6 +#include "repository.h"
7 #include "wrapper.h"
8 #include "gettext.h"
9 #include "loose.h"
@@ -142,8 +141,8 @@ int repo_write_loose_object_map(struct repository *repo)
141
142 for (; iter != kh_end(map); iter++) {
143 if (kh_exist(map, iter)) {
145 - if (oideq(&kh_key(map, iter), the_hash_algo->empty_tree) ||
146 - oideq(&kh_key(map, iter), the_hash_algo->empty_blob))
144 + if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||
145 + oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))
146 continue;
147 strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)), oid_to_hex(kh_value(map, iter)));
148 if (write_in_full(fd, buf.buf, buf.len) < 0)