Skip to content

Commit 63e05f9

Browse files
avargitster
authored andcommitted
object-file API: return "void", not "int" from hash_object_file()
The hash_object_file() function added in abdc3fc (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbea0dd commit 63e05f9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

object-file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,14 +1836,13 @@ static int write_buffer(int fd, const void *buf, size_t len)
18361836
return 0;
18371837
}
18381838

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,
18401840
unsigned long len, const char *type,
18411841
struct object_id *oid)
18421842
{
18431843
char hdr[MAX_HEADER_LEN];
18441844
int hdrlen = sizeof(hdr);
18451845
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
1846-
return 0;
18471846
}
18481847

18491848
/* Finalize a file on disk, and close it. */
@@ -2118,7 +2117,7 @@ static int index_mem(struct index_state *istate,
21182117
enum object_type type,
21192118
const char *path, unsigned flags)
21202119
{
2121-
int ret;
2120+
int ret = 0;
21222121
int re_allocated = 0;
21232122
int write_object = flags & HASH_WRITE_OBJECT;
21242123

@@ -2148,8 +2147,9 @@ static int index_mem(struct index_state *istate,
21482147
if (write_object)
21492148
ret = write_object_file(buf, size, type_name(type), oid);
21502149
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+
21532153
if (re_allocated)
21542154
free(buf);
21552155
return ret;
@@ -2161,7 +2161,7 @@ static int index_stream_convert_blob(struct index_state *istate,
21612161
const char *path,
21622162
unsigned flags)
21632163
{
2164-
int ret;
2164+
int ret = 0;
21652165
const int write_object = flags & HASH_WRITE_OBJECT;
21662166
struct strbuf sbuf = STRBUF_INIT;
21672167

@@ -2175,8 +2175,8 @@ static int index_stream_convert_blob(struct index_state *istate,
21752175
ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB),
21762176
oid);
21772177
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);
21802180
strbuf_release(&sbuf);
21812181
return ret;
21822182
}

object-store.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ static inline void *repo_read_object_file(struct repository *r,
245245
/* Read and unpack an object file into memory, write memory to an object file */
246246
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
247247

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);
251251

252252
int write_object_file_flags(const void *buf, unsigned long len,
253253
const char *type, struct object_id *oid,

0 commit comments

Comments
 (0)