builtin/update-index: convert to using the_hash_algo
Switch from using GIT_SHA1_HEXSZ to the_hash_algo to make the parsing of the index information hash independent. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jul 16, 2018 at 01:28 UTC
1928c9449e600e83de122b3fde7bb0664eee3fa5
1 file changed
+5
-4
builtin/update-index.c
+5
-4
@@ -492,6 +492,7 @@ static void update_one(const char *path)
492
493
static void read_index_info(int nul_term_line)
494
{
495
+ const int hexsz = the_hash_algo->hexsz;
496
struct strbuf buf = STRBUF_INIT;
497
struct strbuf uq = STRBUF_INIT;
498
strbuf_getline_fn getline_fn;
@@ -529,7 +530,7 @@ static void read_index_info(int nul_term_line)
530
mode = ul;
531
532
tab = strchr(ptr, '\t');
532
- if (!tab || tab - ptr < GIT_SHA1_HEXSZ + 1)
533
+ if (!tab || tab - ptr < hexsz + 1)
534
goto bad_line;
535
536
if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
@@ -542,8 +543,8 @@ static void read_index_info(int nul_term_line)
543
ptr = tab + 1; /* point at the head of path */
544
}
545
545
- if (get_oid_hex(tab - GIT_SHA1_HEXSZ, &oid) ||
546
- tab[-(GIT_SHA1_HEXSZ + 1)] != ' ')
546
+ if (get_oid_hex(tab - hexsz, &oid) ||
547
+ tab[-(hexsz + 1)] != ' ')
548
goto bad_line;
549
550
path_name = ptr;
@@ -571,7 +572,7 @@ static void read_index_info(int nul_term_line)
572
* ptr[-1] points at tab,
573
* ptr[-41] is at the beginning of sha1
574
*/
574
- ptr[-(GIT_SHA1_HEXSZ + 2)] = ptr[-1] = 0;
575
+ ptr[-(hexsz + 2)] = ptr[-1] = 0;
576
if (add_cacheinfo(mode, &oid, path_name, stage))
577
die("git update-index: unable to update %s",
578
path_name);