object-file API: return "void", not "int" from hash_object_file()

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>

Ævar Arnfjörð Bjarmason committed Feb 5, 2022 at 00:48 UTC 63e05f90562cc8db5c450dbceeab6677b6e5351f
2 files changed +11 -11
object-file.c
+8 -8
@@ -1836,14 +1836,13 @@ static int write_buffer(int fd, const void *buf, size_t len)
1836 return 0;
1837 }
1838
1839 -int hash_object_file(const struct git_hash_algo *algo, const void *buf,
1839 +void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1840 unsigned long len, const char *type,
1841 struct object_id *oid)
1842 {
1843 char hdr[MAX_HEADER_LEN];
1844 int hdrlen = sizeof(hdr);
1845 write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
1846 - return 0;
1846 }
1847
1848 /* Finalize a file on disk, and close it. */
@@ -2118,7 +2117,7 @@ static int index_mem(struct index_state *istate,
2117 enum object_type type,
2118 const char *path, unsigned flags)
2119 {
2121 - int ret;
2120 + int ret = 0;
2121 int re_allocated = 0;
2122 int write_object = flags & HASH_WRITE_OBJECT;
2123
@@ -2148,8 +2147,9 @@ static int index_mem(struct index_state *istate,
2147 if (write_object)
2148 ret = write_object_file(buf, size, type_name(type), oid);
2149 else
2151 - ret = hash_object_file(the_hash_algo, buf, size,
2152 - type_name(type), oid);
2150 + hash_object_file(the_hash_algo, buf, size, type_name(type),
2151 + oid);
2152 +
2153 if (re_allocated)
2154 free(buf);
2155 return ret;
@@ -2161,7 +2161,7 @@ static int index_stream_convert_blob(struct index_state *istate,
2161 const char *path,
2162 unsigned flags)
2163 {
2164 - int ret;
2164 + int ret = 0;
2165 const int write_object = flags & HASH_WRITE_OBJECT;
2166 struct strbuf sbuf = STRBUF_INIT;
2167
@@ -2175,8 +2175,8 @@ static int index_stream_convert_blob(struct index_state *istate,
2175 ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
2176 oid);
2177 else
2178 - ret = hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
2179 - type_name(OBJ_BLOB), oid);
2178 + hash_object_file(the_hash_algo, sbuf.buf, sbuf.len,
2179 + type_name(OBJ_BLOB), oid);
2180 strbuf_release(&sbuf);
2181 return ret;
2182 }
object-store.h
+3 -3
@@ -245,9 +245,9 @@ static inline void *repo_read_object_file(struct repository *r,
245 /* Read and unpack an object file into memory, write memory to an object file */
246 int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
247
248 -int hash_object_file(const struct git_hash_algo *algo, const void *buf,
249 - unsigned long len, const char *type,
250 - struct object_id *oid);
248 +void hash_object_file(const struct git_hash_algo *algo, const void *buf,
249 + unsigned long len, const char *type,
250 + struct object_id *oid);
251
252 int write_object_file_flags(const void *buf, unsigned long len,
253 const char *type, struct object_id *oid,