Skip to content

Commit 0df0053

Browse files
pks-tgitster
authored andcommitted
object-file: get rid of the_repository in read_loose_object()
The function `read_loose_object()` takes a path to an object file and tries to parse it. As such, the function does not depend on any specific object database but instead acts as an ODB-independent way to read a specific file. As such, all it needs as input is a repository so that we can derive repo settings and the hash algorithm. That repository isn't passed in as a parameter though, as we implicitly depend on the global `the_repository`. Refactor the function so that we pass in the repository as a parameter. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d81712c commit 0df0053

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
633633
oi.sizep = &size;
634634
oi.typep = &type;
635635

636-
if (read_loose_object(path, oid, &real_oid, &contents, &oi) < 0) {
636+
if (read_loose_object(the_repository, path, oid, &real_oid, &contents, &oi) < 0) {
637637
if (contents && !oideq(&real_oid, oid))
638638
err = error(_("%s: hash-path mismatch, found at: %s"),
639639
oid_to_hex(&real_oid), path);

object-file.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,8 @@ static int check_stream_oid(git_zstream *stream,
15351535
return 0;
15361536
}
15371537

1538-
int read_loose_object(const char *path,
1538+
int read_loose_object(struct repository *repo,
1539+
const char *path,
15391540
const struct object_id *expected_oid,
15401541
struct object_id *real_oid,
15411542
void **contents,
@@ -1574,17 +1575,17 @@ int read_loose_object(const char *path,
15741575
}
15751576

15761577
if (*oi->typep == OBJ_BLOB &&
1577-
*size > repo_settings_get_big_file_threshold(the_repository)) {
1578+
*size > repo_settings_get_big_file_threshold(repo)) {
15781579
if (check_stream_oid(&stream, hdr, *size, path, expected_oid,
1579-
the_repository->hash_algo) < 0)
1580+
repo->hash_algo) < 0)
15801581
goto out_inflate;
15811582
} else {
15821583
*contents = unpack_loose_rest(&stream, hdr, *size, expected_oid);
15831584
if (!*contents) {
15841585
error(_("unable to unpack contents of %s"), path);
15851586
goto out_inflate;
15861587
}
1587-
hash_object_file(the_repository->hash_algo,
1588+
hash_object_file(repo->hash_algo,
15881589
*contents, *size,
15891590
*oi->typep, real_oid);
15901591
if (!oideq(expected_oid, real_oid))

object-file.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ int check_and_freshen_file(const char *fn, int freshen);
210210
*
211211
* Returns 0 on success, negative on error (details may be written to stderr).
212212
*/
213-
int read_loose_object(const char *path,
213+
int read_loose_object(struct repository *repo,
214+
const char *path,
214215
const struct object_id *expected_oid,
215216
struct object_id *real_oid,
216217
void **contents,

0 commit comments

Comments
 (0)