builtin/hash-object: convert to struct object_id

Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patryk Obara committed Aug 20, 2017 at 22:09 UTC eab8bf292b9616772245717ce8069ec1a4354bd4
1 file changed +6 -6
builtin/hash-object.c
+6 -6
@@ -16,7 +16,7 @@
16 * needs to bypass the data conversion performed by, and the type
17 * limitation imposed by, index_fd() and its callees.
18 */
19 -static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigned flags)
19 +static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags)
20 {
21 struct strbuf buf = STRBUF_INIT;
22 int ret;
@@ -24,7 +24,7 @@ static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigne
24 if (strbuf_read(&buf, fd, 4096) < 0)
25 ret = -1;
26 else
27 - ret = hash_sha1_file_literally(buf.buf, buf.len, type, sha1, flags);
27 + ret = hash_sha1_file_literally(buf.buf, buf.len, type, oid->hash, flags);
28 strbuf_release(&buf);
29 return ret;
30 }
@@ -33,16 +33,16 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
33 int literally)
34 {
35 struct stat st;
36 - unsigned char sha1[20];
36 + struct object_id oid;
37
38 if (fstat(fd, &st) < 0 ||
39 (literally
40 - ? hash_literally(sha1, fd, type, flags)
41 - : index_fd(sha1, fd, &st, type_from_string(type), path, flags)))
40 + ? hash_literally(&oid, fd, type, flags)
41 + : index_fd(oid.hash, fd, &st, type_from_string(type), path, flags)))
42 die((flags & HASH_WRITE_OBJECT)
43 ? "Unable to add %s to database"
44 : "Unable to hash %s", path);
45 - printf("%s\n", sha1_to_hex(sha1));
45 + printf("%s\n", oid_to_hex(&oid));
46 maybe_flush_or_die(stdout, "hash to stdout");
47 }
48