pack-write: pass hash_algo to internal functions
The internal functions `write_rev_trailer()`, `write_rev_trailer()`, `write_mtimes_header()` and write_mtimes_trailer()` use the global `the_hash_algo` variable to access the repository's hash function. Pass the hash_algo down from callers, all of which already have access to the variable. This removes all global variables from the 'pack-write.c' file, so remove the 'USE_THE_REPOSITORY_VARIABLE' macro. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Jan 19, 2025 at 12:19 UTC
8705c9bd139028aae148251420da27c9bf1c4745
1 file changed
+16
-14
pack-write.c
+16
-14
@@ -1,5 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
2
-
1
#include "git-compat-util.h"
2
#include "environment.h"
3
#include "gettext.h"
@@ -211,9 +209,10 @@ static void write_rev_index_positions(struct hashfile *f,
209
hashwrite_be32(f, pack_order[i]);
210
}
211
214
-static void write_rev_trailer(struct hashfile *f, const unsigned char *hash)
212
+static void write_rev_trailer(const struct git_hash_algo *hash_algo,
213
+ struct hashfile *f, const unsigned char *hash)
214
{
216
- hashwrite(f, hash, the_hash_algo->rawsz);
215
+ hashwrite(f, hash, hash_algo->rawsz);
216
}
217
218
char *write_rev_file(const struct git_hash_algo *hash_algo,
@@ -286,7 +285,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
285
write_rev_header(hash_algo, f);
286
287
write_rev_index_positions(f, pack_order, nr_objects);
289
- write_rev_trailer(f, hash);
288
+ write_rev_trailer(hash_algo, f, hash);
289
290
if (adjust_shared_perm(path) < 0)
291
die(_("failed to make %s readable"), path);
@@ -298,11 +297,12 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
297
return path;
298
}
299
301
-static void write_mtimes_header(struct hashfile *f)
300
+static void write_mtimes_header(const struct git_hash_algo *hash_algo,
301
+ struct hashfile *f)
302
{
303
hashwrite_be32(f, MTIMES_SIGNATURE);
304
hashwrite_be32(f, MTIMES_VERSION);
305
- hashwrite_be32(f, oid_version(the_hash_algo));
305
+ hashwrite_be32(f, oid_version(hash_algo));
306
}
307
308
/*
@@ -322,12 +322,14 @@ static void write_mtimes_objects(struct hashfile *f,
322
}
323
}
324
325
-static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
325
+static void write_mtimes_trailer(const struct git_hash_algo *hash_algo,
326
+ struct hashfile *f, const unsigned char *hash)
327
{
327
- hashwrite(f, hash, the_hash_algo->rawsz);
328
+ hashwrite(f, hash, hash_algo->rawsz);
329
}
330
330
-static char *write_mtimes_file(struct packing_data *to_pack,
331
+static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
332
+ struct packing_data *to_pack,
333
struct pack_idx_entry **objects,
334
uint32_t nr_objects,
335
const unsigned char *hash)
@@ -344,9 +346,9 @@ static char *write_mtimes_file(struct packing_data *to_pack,
346
mtimes_name = strbuf_detach(&tmp_file, NULL);
347
f = hashfd(fd, mtimes_name);
348
347
- write_mtimes_header(f);
349
+ write_mtimes_header(hash_algo, f);
350
write_mtimes_objects(f, to_pack, objects, nr_objects);
349
- write_mtimes_trailer(f, hash);
351
+ write_mtimes_trailer(hash_algo, f, hash);
352
353
if (adjust_shared_perm(mtimes_name) < 0)
354
die(_("failed to make %s readable"), mtimes_name);
@@ -575,8 +577,8 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
577
hash, pack_idx_opts->flags);
578
579
if (pack_idx_opts->flags & WRITE_MTIMES) {
578
- mtimes_tmp_name = write_mtimes_file(to_pack, written_list,
579
- nr_written,
580
+ mtimes_tmp_name = write_mtimes_file(hash_algo, to_pack,
581
+ written_list, nr_written,
582
hash);
583
}
584