]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 26 Mar 2017 16:01:24 +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 40 hex characters, use the
constant GIT_MAX_HEXSZ, which is designed to be suitable for
allocations, instead of GIT_SHA1_HEXSZ.  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>
bisect.c
builtin/blame.c
builtin/merge-index.c
builtin/merge.c
builtin/rev-list.c
diff.c
hex.c
sha1_file.c
sha1_name.c
transport.c

index 30808cadf7613d73cae2e4caaedd922ba9a48ca0..21c3e34636a79bab7849263162df407d7b19153d 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -682,7 +682,7 @@ static int is_expected_rev(const struct object_id *oid)
 
 static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
 {
-       char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
+       char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 
        memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
        update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
index f7aa95f4babaab904443784eccdaa3b219bd2b08..07506a3e457d1540acb7700e4677d715d6842735 100644 (file)
@@ -1890,7 +1890,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
        int cnt;
        const char *cp;
        struct origin *suspect = ent->suspect;
-       char hex[GIT_SHA1_HEXSZ + 1];
+       char hex[GIT_MAX_HEXSZ + 1];
 
        oid_to_hex_r(hex, &suspect->commit->object.oid);
        printf("%s %d %d %d\n",
@@ -1928,7 +1928,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
        const char *cp;
        struct origin *suspect = ent->suspect;
        struct commit_info ci;
-       char hex[GIT_SHA1_HEXSZ + 1];
+       char hex[GIT_MAX_HEXSZ + 1];
        int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
 
        get_commit_info(suspect->commit, &ci, 1);
index 2d1b6db6bd7a33f838a50deceb108ee1ad468db1..c99443b095bd8abbe02d4ea87a452d916681c53f 100644 (file)
@@ -9,7 +9,7 @@ static int merge_entry(int pos, const char *path)
 {
        int found;
        const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
-       char hexbuf[4][GIT_SHA1_HEXSZ + 1];
+       char hexbuf[4][GIT_MAX_HEXSZ + 1];
        char ownbuf[4][60];
 
        if (pos >= active_nr)
index 7554b8d4127ada8261d1f913c6215e93ca42ef7d..a2cceea3fb0f45372cc113eeb335756b44c9eed0 100644 (file)
@@ -1296,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (verify_signatures) {
                for (p = remoteheads; p; p = p->next) {
                        struct commit *commit = p->item;
-                       char hex[GIT_SHA1_HEXSZ + 1];
+                       char hex[GIT_MAX_HEXSZ + 1];
                        struct signature_check signature_check;
                        memset(&signature_check, 0, sizeof(signature_check));
 
index 0aa93d58919742852b05b952e8e35b5270f74ba8..bcf77f0b8a201278f0887933e568937473eb7251 100644 (file)
@@ -212,7 +212,7 @@ static void print_var_int(const char *var, int val)
 static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 {
        int cnt, flags = info->flags;
-       char hex[GIT_SHA1_HEXSZ + 1] = "";
+       char hex[GIT_MAX_HEXSZ + 1] = "";
        struct commit_list *tried;
        struct rev_info *revs = info->revs;
 
diff --git a/diff.c b/diff.c
index a628ac3a95108ca79aef0b41b7051ab2fcbe693a..330b640c684cf8e718f831c5bf4ef9e95c902bdb 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -398,7 +398,7 @@ static struct diff_tempfile {
         */
        const char *name;
 
-       char hex[GIT_SHA1_HEXSZ + 1];
+       char hex[GIT_MAX_HEXSZ + 1];
        char mode[10];
 
        /*
@@ -4219,7 +4219,7 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
         * uniqueness across all objects (statistically speaking).
         */
        if (abblen < GIT_SHA1_HEXSZ - 3) {
-               static char hex[GIT_SHA1_HEXSZ + 1];
+               static char hex[GIT_MAX_HEXSZ + 1];
                if (len < abblen && abblen <= len + 2)
                        xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
                else
diff --git a/hex.c b/hex.c
index eab7b626ee0c36a7cb48d251cfc2ea885461fe28..28b44118cbf2c75b26d017a34ecfdf65dbf4c7eb 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -85,7 +85,7 @@ char *oid_to_hex_r(char *buffer, const struct object_id *oid)
 char *sha1_to_hex(const unsigned char *sha1)
 {
        static int bufno;
-       static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
+       static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
        bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
        return sha1_to_hex_r(hexbuffer[bufno], sha1);
 }
index 71063890ffe9cfe33f876dd8b2306458323c6f30..e763000d34e4793be026de3b406c1954ea7d18c4 100644 (file)
@@ -3759,7 +3759,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
                strbuf_addf(path, "/%s", de->d_name);
 
                if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2)  {
-                       char hex[GIT_SHA1_HEXSZ+1];
+                       char hex[GIT_MAX_HEXSZ+1];
                        struct object_id oid;
 
                        snprintf(hex, sizeof(hex), "%02x%s",
index cda9e49b12e7128dd22a8ccbaff437cb7db34d92..964201bc26d48b111faf9d5ff2b892961e980602 100644 (file)
@@ -15,7 +15,7 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
 
 struct disambiguate_state {
        int len; /* length of prefix in hex chars */
-       char hex_pfx[GIT_SHA1_HEXSZ + 1];
+       char hex_pfx[GIT_MAX_HEXSZ + 1];
        unsigned char bin_pfx[GIT_SHA1_RAWSZ];
 
        disambiguate_hint_fn fn;
@@ -80,7 +80,7 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
 static void find_short_object_filename(struct disambiguate_state *ds)
 {
        struct alternate_object_database *alt;
-       char hex[GIT_SHA1_HEXSZ];
+       char hex[GIT_MAX_HEXSZ];
        static struct alternate_object_database *fakeent;
 
        if (!fakeent) {
@@ -509,7 +509,7 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
 const char *find_unique_abbrev(const unsigned char *sha1, int len)
 {
        static int bufno;
-       static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
+       static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
        char *hex = hexbuffer[bufno];
        bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
        find_unique_abbrev_r(hex, sha1, len);
index 417ed7f19f5fcec5fdf9828749e1e40b207a44e7..8a90b0c29b1557b631b6f679add93261f8288f7e 100644 (file)
@@ -447,7 +447,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
 
 static int measure_abbrev(const struct object_id *oid, int sofar)
 {
-       char hex[GIT_SHA1_HEXSZ + 1];
+       char hex[GIT_MAX_HEXSZ + 1];
        int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
 
        return (w < sofar) ? sofar : w;