upload-pack: express constants in terms of the_hash_algo

Convert all uses of the GIT_SHA1_HEXSZ to use the_hash_algo so that they are appropriate for any given hash length. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 15, 2018 at 00:01 UTC f690b6b03049e8f564aa0a1abbde5ec0731c5774
1 file changed +7 -6
upload-pack.c
+7 -6
@@ -443,6 +443,7 @@ static int do_reachable_revlist(struct child_process *cmd,
443 struct object *o;
444 char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
445 int i;
446 + const unsigned hexsz = the_hash_algo->hexsz;
447
448 cmd->argv = argv;
449 cmd->git_cmd = 1;
@@ -461,7 +462,7 @@ static int do_reachable_revlist(struct child_process *cmd,
462 goto error;
463
464 namebuf[0] = '^';
464 - namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
465 + namebuf[hexsz + 1] = '\n';
466 for (i = get_max_object_index(); 0 < i; ) {
467 o = get_indexed_object(--i);
468 if (!o)
@@ -470,11 +471,11 @@ static int do_reachable_revlist(struct child_process *cmd,
471 o->flags &= ~TMP_MARK;
472 if (!is_our_ref(o))
473 continue;
473 - memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
474 - if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
474 + memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
475 + if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
476 goto error;
477 }
477 - namebuf[GIT_SHA1_HEXSZ] = '\n';
478 + namebuf[hexsz] = '\n';
479 for (i = 0; i < src->nr; i++) {
480 o = src->objects[i].item;
481 if (is_our_ref(o)) {
@@ -484,8 +485,8 @@ static int do_reachable_revlist(struct child_process *cmd,
485 }
486 if (reachable && o->type == OBJ_COMMIT)
487 o->flags |= TMP_MARK;
487 - memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
488 - if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
488 + memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
489 + if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
490 goto error;
491 }
492 close(cmd->in);