Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ

Since we will likely be introducing a new hash function at some point, and that hash function might be longer than 20 bytes, use the constant GIT_MAX_RAWSZ, which is designed to be suitable for allocations, instead of GIT_SHA1_RAWSZ. This will ease the transition down the line by distinguishing between places where we need to allocate memory suitable for the largest hash from those where we need to handle the current hash. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 26, 2017 at 16:01 UTC cd02599c480570484ec0a38a5bf66ac69ee3dd19
8 files changed +10 -10
builtin/patch-id.c
+1 -1
@@ -55,7 +55,7 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
55
56 static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
57 {
58 - unsigned char hash[GIT_SHA1_RAWSZ];
58 + unsigned char hash[GIT_MAX_RAWSZ];
59 unsigned short carry = 0;
60 int i;
61
builtin/receive-pack.c
+1 -1
@@ -1162,7 +1162,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
1162 const char *dst_name;
1163 struct string_list_item *item;
1164 struct command *dst_cmd;
1165 - unsigned char sha1[GIT_SHA1_RAWSZ];
1165 + unsigned char sha1[GIT_MAX_RAWSZ];
1166 int flag;
1167
1168 strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
cache.h
+1 -1
@@ -968,7 +968,7 @@ extern char *sha1_pack_index_name(const unsigned char *sha1);
968 extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
969 extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
970
971 -extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
971 +extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
972 extern const struct object_id null_oid;
973
974 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
patch-ids.c
+1 -1
@@ -71,7 +71,7 @@ static int init_patch_id_entry(struct patch_id *patch,
71 struct commit *commit,
72 struct patch_ids *ids)
73 {
74 - unsigned char header_only_patch_id[GIT_SHA1_RAWSZ];
74 + unsigned char header_only_patch_id[GIT_MAX_RAWSZ];
75
76 patch->commit = commit;
77 if (commit_patch_id(commit, &ids->diffopts, header_only_patch_id, 1))
patch-ids.h
+1 -1
@@ -3,7 +3,7 @@
3
4 struct patch_id {
5 struct hashmap_entry ent;
6 - unsigned char patch_id[GIT_SHA1_RAWSZ];
6 + unsigned char patch_id[GIT_MAX_RAWSZ];
7 struct commit *commit;
8 };
9
sha1_file.c
+2 -2
@@ -1606,7 +1606,7 @@ static void mark_bad_packed_object(struct packed_git *p,
1606 if (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))
1607 return;
1608 p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
1609 - st_mult(GIT_SHA1_RAWSZ,
1609 + st_mult(GIT_MAX_RAWSZ,
1610 st_add(p->num_bad_objects, 1)));
1611 hashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1);
1612 p->num_bad_objects++;
@@ -3913,7 +3913,7 @@ static int check_stream_sha1(git_zstream *stream,
3913 const unsigned char *expected_sha1)
3914 {
3915 git_SHA_CTX c;
3916 - unsigned char real_sha1[GIT_SHA1_RAWSZ];
3916 + unsigned char real_sha1[GIT_MAX_RAWSZ];
3917 unsigned char buf[4096];
3918 unsigned long total_read;
3919 int status = Z_OK;
sha1_name.c
+2 -2
@@ -16,11 +16,11 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
16 struct disambiguate_state {
17 int len; /* length of prefix in hex chars */
18 char hex_pfx[GIT_MAX_HEXSZ + 1];
19 - unsigned char bin_pfx[GIT_SHA1_RAWSZ];
19 + unsigned char bin_pfx[GIT_MAX_RAWSZ];
20
21 disambiguate_hint_fn fn;
22 void *cb_data;
23 - unsigned char candidate[GIT_SHA1_RAWSZ];
23 + unsigned char candidate[GIT_MAX_RAWSZ];
24 unsigned candidate_exists:1;
25 unsigned candidate_checked:1;
26 unsigned candidate_ok:1;
wt-status.h
+1 -1
@@ -80,7 +80,7 @@ struct wt_status {
80 int hints;
81
82 enum wt_status_format status_format;
83 - unsigned char sha1_commit[GIT_SHA1_RAWSZ]; /* when not Initial */
83 + unsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */
84
85 /* These are computed during processing of the individual sections */
86 int commitable;