]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file API: return "void", not "int" from hash_object_file()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 4 Feb 2022 23:48:24 +0000 (00:48 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 26 Feb 2022 01:16:31 +0000 (17:16 -0800)
The hash_object_file() function added in abdc3fc8421 (Add
hash_sha1_file(), 2006-10-14) did not have a meaningful return value,
and it never has.

One was seemingly added to avoid adding braces to the "ret = "
assignments being modified here. Let's instead assign "0" to the "ret"
variables at the beginning of the relevant functions, and have them
return "void".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
object-store.h

index ecc77973292df6f03844b454252a959d494fc279..eeb6814780ad6a6d51768d99fbd19157b525a53f 100644 (file)
@@ -1836,14 +1836,13 @@ static int write_buffer(int fd, const void *buf, size_t len)
        return 0;
 }
 
-int hash_object_file(const struct git_hash_algo *algo, const void *buf,
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
                     unsigned long len, const char *type,
                     struct object_id *oid)
 {
        char hdr[MAX_HEADER_LEN];
        int hdrlen = sizeof(hdr);
        write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
-       return 0;
 }
 
 /* Finalize a file on disk, and close it. */
@@ -2118,7 +2117,7 @@ static int index_mem(struct index_state *istate,
                     enum object_type type,
                     const char *path, unsigned flags)
 {
-       int ret;
+       int ret = 0;
        int re_allocated = 0;
        int write_object = flags & HASH_WRITE_OBJECT;
 
@@ -2148,8 +2147,9 @@ static int index_mem(struct index_state *istate,
        if (write_object)
                ret = write_object_file(buf, size, type_name(type), oid);
        else
-               ret = hash_object_file(the_hash_algo, buf, size,
-                                      type_name(type), oid);
+               hash_object_file(the_hash_algo, buf, size, type_name(type),
+                                oid);
+
        if (re_allocated)
                free(buf);
        return ret;
@@ -2161,7 +2161,7 @@ static int index_stream_convert_blob(struct index_state *istate,
                                     const char *path,
                                     unsigned flags)
 {
-       int ret;
+       int ret = 0;
        const int write_object = flags & HASH_WRITE_OBJECT;
        struct strbuf sbuf = STRBUF_INIT;
 
@@ -2175,8 +2175,8 @@ static int index_stream_convert_blob(struct index_state *istate,
                ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
                                        oid);
        else
-               ret = hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
-                                      type_name(OBJ_BLOB), oid);
+               hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
+                                type_name(OBJ_BLOB), oid);
        strbuf_release(&sbuf);
        return ret;
 }
index 6f89482df030cb28c91a7d2620903473e661370f..44f6868cc9c46ee1367b237fb66cdb8e0acbedf6 100644 (file)
@@ -245,9 +245,9 @@ static inline void *repo_read_object_file(struct repository *r,
 /* Read and unpack an object file into memory, write memory to an object file */
 int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
 
-int hash_object_file(const struct git_hash_algo *algo, const void *buf,
-                    unsigned long len, const char *type,
-                    struct object_id *oid);
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+                     unsigned long len, const char *type,
+                     struct object_id *oid);
 
 int write_object_file_flags(const void *buf, unsigned long len,
                            const char *type, struct object_id *oid,