Skip to content

Commit 55dc227

Browse files
bk2204gitster
authored andcommitted
upload-pack: replace use of several hard-coded constants
Update several uses of hard-coded 40-based constants to use either the_hash_algo or GIT_MAX_HEXSZ, as appropriate. Replace a combined use of oid_to_hex and memcpy with oid_to_hex_r, which not only avoids the need for a constant, but is more efficient. Make use of parse_oid_hex to eliminate the need for constants and simplify the code at the same time. Update some comments to no longer refer to SHA-1 as well. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd52124 commit 55dc227

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

upload-pack.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static int get_common_commits(void)
450450
break;
451451
default:
452452
got_common = 1;
453-
memcpy(last_hex, oid_to_hex(&oid), 41);
453+
oid_to_hex_r(last_hex, &oid);
454454
if (multi_ack == 2)
455455
packet_write_fmt(1, "ACK %s common\n", last_hex);
456456
else if (multi_ack)
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
492492
"rev-list", "--stdin", NULL,
493493
};
494494
struct object *o;
495-
char namebuf[42]; /* ^ + SHA-1 + LF */
495+
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
496496
int i;
497497

498498
cmd->argv = argv;
@@ -561,15 +561,17 @@ static int get_reachable_list(struct object_array *src,
561561
struct child_process cmd = CHILD_PROCESS_INIT;
562562
int i;
563563
struct object *o;
564-
char namebuf[42]; /* ^ + SHA-1 + LF */
564+
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
565+
const unsigned hexsz = the_hash_algo->hexsz;
565566

566567
if (do_reachable_revlist(&cmd, src, reachable) < 0)
567568
return -1;
568569

569-
while ((i = read_in_full(cmd.out, namebuf, 41)) == 41) {
570+
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
570571
struct object_id sha1;
572+
const char *p;
571573

572-
if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
574+
if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
573575
break;
574576

575577
o = lookup_object(sha1.hash);
@@ -820,11 +822,9 @@ static void receive_needs(void)
820822
continue;
821823
}
822824
if (!skip_prefix(line, "want ", &arg) ||
823-
get_oid_hex(arg, &oid_buf))
825+
parse_oid_hex(arg, &oid_buf, &features))
824826
die("git upload-pack: protocol error, "
825-
"expected to get sha, not '%s'", line);
826-
827-
features = arg + 40;
827+
"expected to get object ID, not '%s'", line);
828828

829829
if (parse_feature_request(features, "deepen-relative"))
830830
deepen_relative = 1;

0 commit comments

Comments
 (0)