diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2019-08-18 20:04:02 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-08-19 15:04:57 -0700 |
commit | 28ba1830d0533007d5cbc1110880c6599296029a (patch) | |
tree | ac1d3d17becfa2beac3251469bc861fa52cddd68 | |
parent | 5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff) | |
download | git-28ba1830d0533007d5cbc1110880c6599296029a.tar.gz |
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>
-rw-r--r-- | builtin/replace.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/builtin/replace.c b/builtin/replace.c index 644b21ca8d..4b00f1d84e 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -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); @@ -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++) { |