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>
brian m. carlson committed
Aug 18, 2019 at 20:04 UTC
28ba1830d0533007d5cbc1110880c6599296029a
1 file changed
+4
-3
builtin/replace.c
+4
-3
@@ -272,7 +272,7 @@ static int import_object(struct object_id *oid, enum object_type type,
272
return error(_("unable to spawn mktree"));
273
}
274
275
- if (strbuf_read(&result, cmd.out, 41) < 0) {
275
+ if (strbuf_read(&result, cmd.out, the_hash_algo->hexsz + 1) < 0) {
276
error_errno(_("unable to read from mktree"));
277
close(fd);
278
close(cmd.out);
@@ -358,14 +358,15 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)
358
struct strbuf new_parents = STRBUF_INIT;
359
const char *parent_start, *parent_end;
360
int i;
361
+ const unsigned hexsz = the_hash_algo->hexsz;
362
363
/* find existing parents */
364
parent_start = buf->buf;
364
- parent_start += GIT_SHA1_HEXSZ + 6; /* "tree " + "hex sha1" + "\n" */
365
+ parent_start += hexsz + 6; /* "tree " + "hex sha1" + "\n" */
366
parent_end = parent_start;
367
368
while (starts_with(parent_end, "parent "))
368
- parent_end += 48; /* "parent " + "hex sha1" + "\n" */
369
+ parent_end += hexsz + 8; /* "parent " + "hex sha1" + "\n" */
370
371
/* prepare new parents */
372
for (i = 0; i < argc; i++) {