Skip to content

Commit

Permalink
builtin/replace: make hash size independent
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bk2204 authored and gitster committed Aug 19, 2019
1 parent 5fa0f52 commit 28ba183
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/replace.c
Expand Up @@ -272,7 +272,7 @@ static int import_object(struct object_id *oid, enum object_type type,
return error(_("unable to spawn mktree"));
}

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

/* find existing parents */
parent_start = buf->buf;
parent_start += GIT_SHA1_HEXSZ + 6; /* "tree " + "hex sha1" + "\n" */
parent_start += hexsz + 6; /* "tree " + "hex sha1" + "\n" */
parent_end = parent_start;

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

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

0 comments on commit 28ba183

Please sign in to comment.