Skip to content

Commit 28ba183

Browse files
bk2204gitster
authored andcommitted
builtin/replace: make hash size independent
Instead of using GIT_SHA1_HEXSZ and hard-coded constants, switch to using the_hash_algo. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5fa0f52 commit 28ba183

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/replace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int import_object(struct object_id *oid, enum object_type type,
272272
return error(_("unable to spawn mktree"));
273273
}
274274

275-
if (strbuf_read(&result, cmd.out, 41) < 0) {
275+
if (strbuf_read(&result, cmd.out, the_hash_algo->hexsz + 1) < 0) {
276276
error_errno(_("unable to read from mktree"));
277277
close(fd);
278278
close(cmd.out);
@@ -358,14 +358,15 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
358358
struct strbuf new_parents = STRBUF_INIT;
359359
const char *parent_start, *parent_end;
360360
int i;
361+
const unsigned hexsz = the_hash_algo->hexsz;
361362

362363
/* find existing parents */
363364
parent_start = buf->buf;
364-
parent_start += GIT_SHA1_HEXSZ + 6; /* "tree " + "hex sha1" + "\n" */
365+
parent_start += hexsz + 6; /* "tree " + "hex sha1" + "\n" */
365366
parent_end = parent_start;
366367

367368
while (starts_with(parent_end, "parent "))
368-
parent_end += 48; /* "parent " + "hex sha1" + "\n" */
369+
parent_end += hexsz + 8; /* "parent " + "hex sha1" + "\n" */
369370

370371
/* prepare new parents */
371372
for (i = 0; i < argc; i++) {

0 commit comments

Comments
 (0)