Skip to content

Commit dd724bc

Browse files
bk2204gitster
authored andcommitted
http: eliminate hard-coded constants
Use the_hash_algo to find the right size for parsing pack names. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 70c369c commit dd724bc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

http.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,8 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
20472047
int ret = 0, i = 0;
20482048
char *url, *data;
20492049
struct strbuf buf = STRBUF_INIT;
2050-
unsigned char sha1[20];
2050+
unsigned char hash[GIT_MAX_RAWSZ];
2051+
const unsigned hexsz = the_hash_algo->hexsz;
20512052

20522053
end_url_with_slash(&buf, base_url);
20532054
strbuf_addstr(&buf, "objects/info/packs");
@@ -2063,13 +2064,13 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
20632064
switch (data[i]) {
20642065
case 'P':
20652066
i++;
2066-
if (i + 52 <= buf.len &&
2067+
if (i + hexsz + 12 <= buf.len &&
20672068
starts_with(data + i, " pack-") &&
2068-
starts_with(data + i + 46, ".pack\n")) {
2069-
get_sha1_hex(data + i + 6, sha1);
2070-
fetch_and_setup_pack_index(packs_head, sha1,
2069+
starts_with(data + i + hexsz + 6, ".pack\n")) {
2070+
get_sha1_hex(data + i + 6, hash);
2071+
fetch_and_setup_pack_index(packs_head, hash,
20712072
base_url);
2072-
i += 51;
2073+
i += hexsz + 11;
20732074
break;
20742075
}
20752076
default:

0 commit comments

Comments
 (0)