]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 26 Mar 2017 16:01:25 +0000 (16:01 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2017 05:08:21 +0000 (22:08 -0700)
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>
builtin/patch-id.c
builtin/receive-pack.c
cache.h
patch-ids.c
patch-ids.h
sha1_file.c
sha1_name.c
wt-status.h

index a84d0003a3087c842b6eab6a987a93eebaddec79..81552e02e412b53fcb50ffa6a4d5949acdaac79c 100644 (file)
@@ -55,7 +55,7 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
 
 static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)
 {
-       unsigned char hash[GIT_SHA1_RAWSZ];
+       unsigned char hash[GIT_MAX_RAWSZ];
        unsigned short carry = 0;
        int i;
 
index fb2a090a0ce464cf6f663fa367c4859bd3a5f619..feafb076a41d534d4a503247eadb2661f47b3b3f 100644 (file)
@@ -1162,7 +1162,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
        const char *dst_name;
        struct string_list_item *item;
        struct command *dst_cmd;
-       unsigned char sha1[GIT_SHA1_RAWSZ];
+       unsigned char sha1[GIT_MAX_RAWSZ];
        int flag;
 
        strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
diff --git a/cache.h b/cache.h
index af4b2c78cfbbb2c506e26858038294997a088a16..179bdc5da2ac14f3beb63f82263455f2ac512f51 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -968,7 +968,7 @@ extern char *sha1_pack_index_name(const unsigned char *sha1);
 extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
 extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
 
-extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
+extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
index ce285c2e0c552ecf725c87052846d755507bd9db..fa8f11de82657c3edf4e5c0869d76ae6f12b57bb 100644 (file)
@@ -71,7 +71,7 @@ static int init_patch_id_entry(struct patch_id *patch,
                               struct commit *commit,
                               struct patch_ids *ids)
 {
-       unsigned char header_only_patch_id[GIT_SHA1_RAWSZ];
+       unsigned char header_only_patch_id[GIT_MAX_RAWSZ];
 
        patch->commit = commit;
        if (commit_patch_id(commit, &ids->diffopts, header_only_patch_id, 1))
index 0f34ea11eadffea14620ea2ad45d69894469aef7..b9e5751f8e2f6ef17bfa444fe6d8f3f2c6b7bb85 100644 (file)
@@ -3,7 +3,7 @@
 
 struct patch_id {
        struct hashmap_entry ent;
-       unsigned char patch_id[GIT_SHA1_RAWSZ];
+       unsigned char patch_id[GIT_MAX_RAWSZ];
        struct commit *commit;
 };
 
index e763000d34e4793be026de3b406c1954ea7d18c4..b4666ee5c244cacefb08f1f41968c3f3524cf94b 100644 (file)
@@ -1606,7 +1606,7 @@ static void mark_bad_packed_object(struct packed_git *p,
                if (!hashcmp(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))
                        return;
        p->bad_object_sha1 = xrealloc(p->bad_object_sha1,
-                                     st_mult(GIT_SHA1_RAWSZ,
+                                     st_mult(GIT_MAX_RAWSZ,
                                              st_add(p->num_bad_objects, 1)));
        hashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1);
        p->num_bad_objects++;
@@ -3913,7 +3913,7 @@ static int check_stream_sha1(git_zstream *stream,
                             const unsigned char *expected_sha1)
 {
        git_SHA_CTX c;
-       unsigned char real_sha1[GIT_SHA1_RAWSZ];
+       unsigned char real_sha1[GIT_MAX_RAWSZ];
        unsigned char buf[4096];
        unsigned long total_read;
        int status = Z_OK;
index 964201bc26d48b111faf9d5ff2b892961e980602..3db166b40b768910fb62c788bff7921672a3cf16 100644 (file)
@@ -16,11 +16,11 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
 struct disambiguate_state {
        int len; /* length of prefix in hex chars */
        char hex_pfx[GIT_MAX_HEXSZ + 1];
-       unsigned char bin_pfx[GIT_SHA1_RAWSZ];
+       unsigned char bin_pfx[GIT_MAX_RAWSZ];
 
        disambiguate_hint_fn fn;
        void *cb_data;
-       unsigned char candidate[GIT_SHA1_RAWSZ];
+       unsigned char candidate[GIT_MAX_RAWSZ];
        unsigned candidate_exists:1;
        unsigned candidate_checked:1;
        unsigned candidate_ok:1;
index 54fec77032dc9c5d0f7af4226afc886797a209c4..6018c627b1e40e5c36d0c0c12eff1f262cb439b4 100644 (file)
@@ -80,7 +80,7 @@ struct wt_status {
        int hints;
 
        enum wt_status_format status_format;
-       unsigned char sha1_commit[GIT_SHA1_RAWSZ]; /* when not Initial */
+       unsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */
 
        /* These are computed during processing of the individual sections */
        int commitable;