Skip to content

Commit 1928c94

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ae2e2a commit 1928c94

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin/update-index.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ static void update_one(const char *path)
492492

493493
static void read_index_info(int nul_term_line)
494494
{
495+
const int hexsz = the_hash_algo->hexsz;
495496
struct strbuf buf = STRBUF_INIT;
496497
struct strbuf uq = STRBUF_INIT;
497498
strbuf_getline_fn getline_fn;
@@ -529,7 +530,7 @@ static void read_index_info(int nul_term_line)
529530
mode = ul;
530531

531532
tab = strchr(ptr, '\t');
532-
if (!tab || tab - ptr < GIT_SHA1_HEXSZ + 1)
533+
if (!tab || tab - ptr < hexsz + 1)
533534
goto bad_line;
534535

535536
if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
@@ -542,8 +543,8 @@ static void read_index_info(int nul_term_line)
542543
ptr = tab + 1; /* point at the head of path */
543544
}
544545

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)] != ' ')
547548
goto bad_line;
548549

549550
path_name = ptr;
@@ -571,7 +572,7 @@ static void read_index_info(int nul_term_line)
571572
* ptr[-1] points at tab,
572573
* ptr[-41] is at the beginning of sha1
573574
*/
574-
ptr[-(GIT_SHA1_HEXSZ + 2)] = ptr[-1] = 0;
575+
ptr[-(hexsz + 2)] = ptr[-1] = 0;
575576
if (add_cacheinfo(mode, &oid, path_name, stage))
576577
die("git update-index: unable to update %s",
577578
path_name);

0 commit comments

Comments
 (0)