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

[PATCH v2 04/12] builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 1, 2018, 02:18 UTC
Message-ID
<20180201021848.533188-5-sandals@crustytoothpaste.net>
In-Reply-To
<20180201021848.533188-1-sandals@crustytoothpaste.net>

Switch various uses of explicit calls to SHA-1 into references to the_hash_algo to better abstract away the various uses of it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/unpack-objects.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 62ea264c46..813ca31979 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -21,7 +21,7 @@ static unsigned char buffer[4096];
 static unsigned int offset, len;
 static off_t consumed_bytes;
 static off_t max_input_size;
-static git_SHA_CTX ctx;
+static git_hash_ctx ctx;
 static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
 
 /*
@@ -62,7 +62,7 @@ static void *fill(int min)
 	if (min > sizeof(buffer))
 		die("cannot fill %d bytes", min);
 	if (offset) {
-		git_SHA1_Update(&ctx, buffer, offset);
+		the_hash_algo->update_fn(&ctx, buffer, offset);
 		memmove(buffer, buffer + offset, len);
 		offset = 0;
 	}
@@ -345,8 +345,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
 	struct object_id base_oid;
 
 	if (type == OBJ_REF_DELTA) {
-		hashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ));
-		use(GIT_SHA1_RAWSZ);
+		hashcpy(base_oid.hash, fill(the_hash_algo->rawsz));
+		use(the_hash_algo->rawsz);
 		delta_data = get_data(delta_size);
 		if (dry_run || !delta_data) {
 			free(delta_data);
@@ -564,15 +564,15 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 		/* We don't take any non-flag arguments now.. Maybe some day */
 		usage(unpack_usage);
 	}
-	git_SHA1_Init(&ctx);
+	the_hash_algo->init_fn(&ctx);
 	unpack_all();
-	git_SHA1_Update(&ctx, buffer, offset);
-	git_SHA1_Final(oid.hash, &ctx);
+	the_hash_algo->update_fn(&ctx, buffer, offset);
+	the_hash_algo->final_fn(oid.hash, &ctx);
 	if (strict)
 		write_rest();
-	if (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash))
+	if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
 		die("final sha1 did not match");
-	use(GIT_SHA1_RAWSZ);
+	use(the_hash_algo->rawsz);
 
 	/* Write the last part of the buffer to stdout */
 	while (len) {
Previous: brian m. carlsonNext: brian m. carlson
Message 13 of 19 in “object_id part 11 (the_hash_algo)”
  1. 00/12 object_id part 11 (the_hash_algo)brian m. carlson, Feb 1, 2018
  2. 01/12 hash: move SHA-1 macros to hash.hbrian m. carlson, Feb 1, 2018
  3. Junio C HamanoFeb 2, 2018
  4. 02/12 hash: create union for hash context allocationbrian m. carlson, Feb 1, 2018
  5. 03/12 builtin/index-pack: improve hash function abstractionbrian m. carlson, Feb 1, 2018
  6. 07/12 pack-check: convert various uses of SHA-1 to abstract formsbrian m. carlson, Feb 1, 2018
  7. 06/12 fast-import: switch various uses of SHA-1 to the_hash_algobrian m. carlson, Feb 1, 2018
  8. 08/12 pack-write: switch various SHA-1 values to abstract formsbrian m. carlson, Feb 1, 2018
  9. 12/12 bulk-checkin: abstract SHA-1 usagebrian m. carlson, Feb 1, 2018
  10. 10/12 csum-file: rename sha1file to hashfilebrian m. carlson, Feb 1, 2018
  11. 11/12 csum-file: abstract uses of SHA-1brian m. carlson, Feb 1, 2018
  12. 09/12 read-cache: abstract away uses of SHA-1brian m. carlson, Feb 1, 2018
  13. 04/12 builtin/unpack-objects: switch uses of SHA-1 to the_hash_algobrian m. carlson, Feb 1, 2018
  14. 05/12 sha1_file: switch uses of SHA-1 to the_hash_algobrian m. carlson, Feb 1, 2018
  15. Stefan BellerFeb 1, 2018
  16. Junio C HamanoFeb 2, 2018
  17. brian m. carlsonFeb 6, 2018
  18. Junio C HamanoFeb 6, 2018
  19. hash: update obsolete reference to SHA1_HEADERbrian m. carlson, Feb 8, 2018

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.