[PATCH v4 03/12] add_sought_entry_mem: convert to struct object_id
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Nov 10, 2015, 02:22 UTC
- Message-ID
- <1447122150-672570-4-git-send-email-sandals@crustytoothpaste.net>
- In-Reply-To
- <1447122150-672570-1-git-send-email-sandals@crustytoothpaste.net>
Convert this function to use struct object_id. Express several hardcoded constants in terms of GIT_SHA1_HEXSZ.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> --- builtin/fetch-pack.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 19215b33..cf3019e0 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc, const char *name, int namelen) { struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1); - unsigned char sha1[20]; + struct object_id oid; + const int chunksz = GIT_SHA1_HEXSZ + 1; - if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) { - hashcpy(ref->old_oid.hash, sha1); - name += 41; - namelen -= 41; + if (namelen > chunksz && name[chunksz - 1] == ' ' && + !get_oid_hex(name, &oid)) { + oidcpy(&ref->old_oid, &oid); + name += chunksz; + namelen -= chunksz; } memcpy(ref->name, name, namelen);
-- 2.6.2.409.gb049f0a