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

[PATCH v2 5/5] pack-write: pass hash_algo to internal functions

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 17, 2025, 09:20 UTC
Message-ID
<20250117-kn-the-repo-cleanup-v2-5-a7fdc19688f5@gmail.com>
In-Reply-To
<20250117-kn-the-repo-cleanup-v2-0-a7fdc19688f5@gmail.com>

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 from down as we've added made them available in the previous few commits.

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>
---
 pack-write.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index 09ecbcdb069cc9b0383295798ceb49cbdc632b64..a2faeb1895e41f4c17281380478f1f2cabcc6f24 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
@@ -211,9 +209,10 @@ static void write_rev_index_positions(struct hashfile *f,
 		hashwrite_be32(f, pack_order[i]);
 }
 
-static void write_rev_trailer(struct hashfile *f, const unsigned char *hash)
+static void write_rev_trailer(const struct git_hash_algo *hash_algo,
+			      struct hashfile *f, const unsigned char *hash)
 {
-	hashwrite(f, hash, the_hash_algo->rawsz);
+	hashwrite(f, hash, hash_algo->rawsz);
 }
 
 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,
 	write_rev_header(hash_algo, f);
 
 	write_rev_index_positions(f, pack_order, nr_objects);
-	write_rev_trailer(f, hash);
+	write_rev_trailer(hash_algo, f, hash);
 
 	if (adjust_shared_perm(path) < 0)
 		die(_("failed to make %s readable"), path);
@@ -298,11 +297,12 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
 	return path;
 }
 
-static void write_mtimes_header(struct hashfile *f)
+static void write_mtimes_header(const struct git_hash_algo *hash_algo,
+				struct hashfile *f)
 {
 	hashwrite_be32(f, MTIMES_SIGNATURE);
 	hashwrite_be32(f, MTIMES_VERSION);
-	hashwrite_be32(f, oid_version(the_hash_algo));
+	hashwrite_be32(f, oid_version(hash_algo));
 }
 
 /*
@@ -322,12 +322,14 @@ static void write_mtimes_objects(struct hashfile *f,
 	}
 }
 
-static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
+static void write_mtimes_trailer(const struct git_hash_algo *hash_algo,
+				 struct hashfile *f, const unsigned char *hash)
 {
-	hashwrite(f, hash, the_hash_algo->rawsz);
+	hashwrite(f, hash, hash_algo->rawsz);
 }
 
-static char *write_mtimes_file(struct packing_data *to_pack,
+static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
+			       struct packing_data *to_pack,
 			       struct pack_idx_entry **objects,
 			       uint32_t nr_objects,
 			       const unsigned char *hash)
@@ -344,9 +346,9 @@ static char *write_mtimes_file(struct packing_data *to_pack,
 	mtimes_name = strbuf_detach(&tmp_file, NULL);
 	f = hashfd(fd, mtimes_name);
 
-	write_mtimes_header(f);
+	write_mtimes_header(hash_algo, f);
 	write_mtimes_objects(f, to_pack, objects, nr_objects);
-	write_mtimes_trailer(f, hash);
+	write_mtimes_trailer(hash_algo, f, hash);
 
 	if (adjust_shared_perm(mtimes_name) < 0)
 		die(_("failed to make %s readable"), mtimes_name);
@@ -575,8 +577,8 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
 				      hash, pack_idx_opts->flags);
 
 	if (pack_idx_opts->flags & WRITE_MTIMES) {
-		mtimes_tmp_name = write_mtimes_file(to_pack, written_list,
-						    nr_written,
+		mtimes_tmp_name = write_mtimes_file(hash_algo, to_pack,
+						    written_list, nr_written,
 						    hash);
 	}
 
-- 
2.47.0
Previous: Karthik NayakNext: Patrick Steinhardt
Message 26 of 36 in “pack-write: cleanup usage of global variables”
  1. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak via B4 Relay, Jan 16, 2025
  2. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak via B4 Relay, Jan 16, 2025
  3. Junio C HamanoJan 16, 2025
  4. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak via B4 Relay, Jan 16, 2025
  5. Junio C HamanoJan 16, 2025
  6. Karthik NayakJan 17, 2025
  7. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  8. Patrick SteinhardtJan 16, 2025
  9. Junio C HamanoJan 16, 2025
  10. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  11. Patrick SteinhardtJan 16, 2025
  12. Karthik NayakJan 17, 2025
  13. Junio C HamanoJan 16, 2025
  14. Karthik NayakJan 17, 2025
  15. 5/5 pack-write: pass hash_algo to `write_rev_*()`Karthik Nayak via B4 Relay, Jan 16, 2025
  16. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 17, 2025
  17. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 17, 2025
  18. Toon ClaesJan 17, 2025
  19. Junio C HamanoJan 17, 2025
  20. Karthik NayakJan 19, 2025
  21. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 17, 2025
  22. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 17, 2025
  23. Toon ClaesJan 17, 2025
  24. Karthik NayakJan 19, 2025
  25. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 17, 2025
  26. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 17, 2025
  27. Patrick SteinhardtJan 17, 2025
  28. Karthik NayakJan 17, 2025
  29. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 19, 2025
  30. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 19, 2025
  31. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 19, 2025
  32. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 19, 2025
  33. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 19, 2025
  34. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 19, 2025
  35. Patrick SteinhardtJan 24, 2025
  36. Junio C HamanoJan 24, 2025

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.