builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo

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

brian m. carlson committed Feb 1, 2018 at 02:18 UTC 3206b6bdf6c261633b3712b7549b794aa39a5169
1 file changed +9 -9
builtin/unpack-objects.c
+9 -9
@@ -21,7 +21,7 @@ static unsigned char buffer[4096];
21 static unsigned int offset, len;
22 static off_t consumed_bytes;
23 static off_t max_input_size;
24 -static git_SHA_CTX ctx;
24 +static git_hash_ctx ctx;
25 static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
26
27 /*
@@ -62,7 +62,7 @@ static void *fill(int min)
62 if (min > sizeof(buffer))
63 die("cannot fill %d bytes", min);
64 if (offset) {
65 - git_SHA1_Update(&ctx, buffer, offset);
65 + the_hash_algo->update_fn(&ctx, buffer, offset);
66 memmove(buffer, buffer + offset, len);
67 offset = 0;
68 }
@@ -345,8 +345,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
345 struct object_id base_oid;
346
347 if (type == OBJ_REF_DELTA) {
348 - hashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ));
349 - use(GIT_SHA1_RAWSZ);
348 + hashcpy(base_oid.hash, fill(the_hash_algo->rawsz));
349 + use(the_hash_algo->rawsz);
350 delta_data = get_data(delta_size);
351 if (dry_run || !delta_data) {
352 free(delta_data);
@@ -564,15 +564,15 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
564 /* We don't take any non-flag arguments now.. Maybe some day */
565 usage(unpack_usage);
566 }
567 - git_SHA1_Init(&ctx);
567 + the_hash_algo->init_fn(&ctx);
568 unpack_all();
569 - git_SHA1_Update(&ctx, buffer, offset);
570 - git_SHA1_Final(oid.hash, &ctx);
569 + the_hash_algo->update_fn(&ctx, buffer, offset);
570 + the_hash_algo->final_fn(oid.hash, &ctx);
571 if (strict)
572 write_rest();
573 - if (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash))
573 + if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
574 die("final sha1 did not match");
575 - use(GIT_SHA1_RAWSZ);
575 + use(the_hash_algo->rawsz);
576
577 /* Write the last part of the buffer to stdout */
578 while (len) {