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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
55dc227d16cb0ca79ca25e89433d85bd5f806c22
1 file changed
+9
-9
upload-pack.c
+9
-9
@@ -450,7 +450,7 @@ static int get_common_commits(void)
450
break;
451
default:
452
got_common = 1;
453
- memcpy(last_hex, oid_to_hex(&oid), 41);
453
+ oid_to_hex_r(last_hex, &oid);
454
if (multi_ack == 2)
455
packet_write_fmt(1, "ACK %s common\n", last_hex);
456
else if (multi_ack)
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
492
"rev-list", "--stdin", NULL,
493
};
494
struct object *o;
495
- char namebuf[42]; /* ^ + SHA-1 + LF */
495
+ char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
496
int i;
497
498
cmd->argv = argv;
@@ -561,15 +561,17 @@ static int get_reachable_list(struct object_array *src,
561
struct child_process cmd = CHILD_PROCESS_INIT;
562
int i;
563
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;
566
567
if (do_reachable_revlist(&cmd, src, reachable) < 0)
568
return -1;
569
569
- while ((i = read_in_full(cmd.out, namebuf, 41)) == 41) {
570
+ while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
571
struct object_id sha1;
572
+ const char *p;
573
572
- if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
574
+ if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
575
break;
576
577
o = lookup_object(sha1.hash);
@@ -820,11 +822,9 @@ static void receive_needs(void)
822
continue;
823
}
824
if (!skip_prefix(line, "want ", &arg) ||
823
- get_oid_hex(arg, &oid_buf))
825
+ parse_oid_hex(arg, &oid_buf, &features))
826
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);
828
829
if (parse_feature_request(features, "deepen-relative"))
830
deepen_relative = 1;