Skip to content

Commit 0000d65

Browse files
rscharfegitster
authored andcommitted
object-store: factor out odb_loose_cache()
Add and use a function for loading the entries of a loose object subdirectory for a given object ID. It frees callers from deriving the fanout key; they can use the returned oid_array reference for lookups or forward range scans. Suggested-by: Jeff King <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ecbdaf0 commit 0000d65

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

object-store.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ void add_to_alternates_memory(const char *dir);
5454
*/
5555
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr);
5656

57+
/*
58+
* Populate and return the loose object cache array corresponding to the
59+
* given object ID.
60+
*/
61+
struct oid_array *odb_loose_cache(struct object_directory *odb,
62+
const struct object_id *oid);
63+
5764
struct packed_git {
5865
struct packed_git *next;
5966
struct list_head mru;

sha1-file.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,14 @@ static int open_sha1_file(struct repository *r,
924924
static int quick_has_loose(struct repository *r,
925925
const unsigned char *sha1)
926926
{
927-
int subdir_nr = sha1[0];
928927
struct object_id oid;
929928
struct object_directory *odb;
930929

931930
hashcpy(oid.hash, sha1);
932931

933932
prepare_alt_odb(r);
934933
for (odb = r->objects->odb; odb; odb = odb->next) {
935-
odb_load_loose_cache(odb, subdir_nr);
936-
if (oid_array_lookup(&odb->loose_objects_cache, &oid) >= 0)
934+
if (oid_array_lookup(odb_loose_cache(odb, &oid), &oid) >= 0)
937935
return 1;
938936
}
939937
return 0;
@@ -2152,6 +2150,14 @@ static int append_loose_object(const struct object_id *oid, const char *path,
21522150
return 0;
21532151
}
21542152

2153+
struct oid_array *odb_loose_cache(struct object_directory *odb,
2154+
const struct object_id *oid)
2155+
{
2156+
int subdir_nr = oid->hash[0];
2157+
odb_load_loose_cache(odb, subdir_nr);
2158+
return &odb->loose_objects_cache;
2159+
}
2160+
21552161
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
21562162
{
21572163
struct strbuf buf = STRBUF_INIT;

sha1-name.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ static int match_sha(unsigned, const unsigned char *, const unsigned char *);
8787

8888
static void find_short_object_filename(struct disambiguate_state *ds)
8989
{
90-
int subdir_nr = ds->bin_pfx.hash[0];
9190
struct object_directory *odb;
9291

9392
for (odb = the_repository->objects->odb;
9493
odb && !ds->ambiguous;
9594
odb = odb->next) {
9695
int pos;
96+
struct oid_array *loose_objects;
9797

98-
odb_load_loose_cache(odb, subdir_nr);
99-
pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx);
98+
loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
99+
pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
100100
if (pos < 0)
101101
pos = -1 - pos;
102-
while (!ds->ambiguous && pos < odb->loose_objects_cache.nr) {
102+
while (!ds->ambiguous && pos < loose_objects->nr) {
103103
const struct object_id *oid;
104-
oid = odb->loose_objects_cache.oid + pos;
104+
oid = loose_objects->oid + pos;
105105
if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
106106
break;
107107
update_candidates(ds, oid);

0 commit comments

Comments
 (0)