Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ
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>
brian m. carlson committed
Mar 26, 2017 at 16:01 UTC
dc01505f7f272a44b974e622f75bd592debe9dcb
10 files changed
+14
-14
bisect.c
+1
-1
@@ -682,7 +682,7 @@ static int is_expected_rev(const struct object_id *oid)
682
683
static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
684
{
685
- char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
685
+ char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
686
687
memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
688
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
builtin/blame.c
+2
-2
@@ -1890,7 +1890,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
1890
int cnt;
1891
const char *cp;
1892
struct origin *suspect = ent->suspect;
1893
- char hex[GIT_SHA1_HEXSZ + 1];
1893
+ char hex[GIT_MAX_HEXSZ + 1];
1894
1895
oid_to_hex_r(hex, &suspect->commit->object.oid);
1896
printf("%s %d %d %d\n",
@@ -1928,7 +1928,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1928
const char *cp;
1929
struct origin *suspect = ent->suspect;
1930
struct commit_info ci;
1931
- char hex[GIT_SHA1_HEXSZ + 1];
1931
+ char hex[GIT_MAX_HEXSZ + 1];
1932
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
1933
1934
get_commit_info(suspect->commit, &ci, 1);
builtin/merge-index.c
+1
-1
@@ -9,7 +9,7 @@ static int merge_entry(int pos, const char *path)
9
{
10
int found;
11
const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
12
- char hexbuf[4][GIT_SHA1_HEXSZ + 1];
12
+ char hexbuf[4][GIT_MAX_HEXSZ + 1];
13
char ownbuf[4][60];
14
15
if (pos >= active_nr)
builtin/merge.c
+1
-1
@@ -1296,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1296
if (verify_signatures) {
1297
for (p = remoteheads; p; p = p->next) {
1298
struct commit *commit = p->item;
1299
- char hex[GIT_SHA1_HEXSZ + 1];
1299
+ char hex[GIT_MAX_HEXSZ + 1];
1300
struct signature_check signature_check;
1301
memset(&signature_check, 0, sizeof(signature_check));
1302
builtin/rev-list.c
+1
-1
@@ -212,7 +212,7 @@ static void print_var_int(const char *var, int val)
212
static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
213
{
214
int cnt, flags = info->flags;
215
- char hex[GIT_SHA1_HEXSZ + 1] = "";
215
+ char hex[GIT_MAX_HEXSZ + 1] = "";
216
struct commit_list *tried;
217
struct rev_info *revs = info->revs;
218
diff.c
+2
-2
@@ -398,7 +398,7 @@ static struct diff_tempfile {
398
*/
399
const char *name;
400
401
- char hex[GIT_SHA1_HEXSZ + 1];
401
+ char hex[GIT_MAX_HEXSZ + 1];
402
char mode[10];
403
404
/*
@@ -4219,7 +4219,7 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
4219
* uniqueness across all objects (statistically speaking).
4220
*/
4221
if (abblen < GIT_SHA1_HEXSZ - 3) {
4222
- static char hex[GIT_SHA1_HEXSZ + 1];
4222
+ static char hex[GIT_MAX_HEXSZ + 1];
4223
if (len < abblen && abblen <= len + 2)
4224
xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
4225
else
hex.c
+1
-1
@@ -85,7 +85,7 @@ char *oid_to_hex_r(char *buffer, const struct object_id *oid)
85
char *sha1_to_hex(const unsigned char *sha1)
86
{
87
static int bufno;
88
- static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
88
+ static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
89
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
90
return sha1_to_hex_r(hexbuffer[bufno], sha1);
91
}
sha1_file.c
+1
-1
@@ -3759,7 +3759,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
3759
strbuf_addf(path, "/%s", de->d_name);
3760
3761
if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
3762
- char hex[GIT_SHA1_HEXSZ+1];
3762
+ char hex[GIT_MAX_HEXSZ+1];
3763
struct object_id oid;
3764
3765
snprintf(hex, sizeof(hex), "%02x%s",
sha1_name.c
+3
-3
@@ -15,7 +15,7 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
15
16
struct disambiguate_state {
17
int len; /* length of prefix in hex chars */
18
- char hex_pfx[GIT_SHA1_HEXSZ + 1];
18
+ char hex_pfx[GIT_MAX_HEXSZ + 1];
19
unsigned char bin_pfx[GIT_SHA1_RAWSZ];
20
21
disambiguate_hint_fn fn;
@@ -80,7 +80,7 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
80
static void find_short_object_filename(struct disambiguate_state *ds)
81
{
82
struct alternate_object_database *alt;
83
- char hex[GIT_SHA1_HEXSZ];
83
+ char hex[GIT_MAX_HEXSZ];
84
static struct alternate_object_database *fakeent;
85
86
if (!fakeent) {
@@ -509,7 +509,7 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
509
const char *find_unique_abbrev(const unsigned char *sha1, int len)
510
{
511
static int bufno;
512
- static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
512
+ static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
513
char *hex = hexbuffer[bufno];
514
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
515
find_unique_abbrev_r(hex, sha1, len);
transport.c
+1
-1
@@ -447,7 +447,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
447
448
static int measure_abbrev(const struct object_id *oid, int sofar)
449
{
450
- char hex[GIT_SHA1_HEXSZ + 1];
450
+ char hex[GIT_MAX_HEXSZ + 1];
451
int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
452
453
return (w < sofar) ? sofar : w;