object-store: factor out odb_clear_loose_cache()

Add and use a function for emptying the loose object cache, so callers don't have to know any of its implementation details. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jan 6, 2019 at 17:45 UTC d4e19e516325e211cedb070a487453ad2d1043be
4 files changed +13 -6
object-store.h
+3
@@ -61,6 +61,9 @@ void odb_load_loose_cache(struct object_directory *odb, int subdir_nr);
61 struct oid_array *odb_loose_cache(struct object_directory *odb,
62 const struct object_id *oid);
63
64 +/* Empty the loose object cache for the specified object directory. */
65 +void odb_clear_loose_cache(struct object_directory *odb);
66 +
67 struct packed_git {
68 struct packed_git *next;
69 struct list_head mru;
object.c
+1 -1
@@ -485,7 +485,7 @@ struct raw_object_store *raw_object_store_new(void)
485 static void free_object_directory(struct object_directory *odb)
486 {
487 free(odb->path);
488 - oid_array_clear(&odb->loose_objects_cache);
488 + odb_clear_loose_cache(odb);
489 free(odb);
490 }
491
packfile.c
+2 -5
@@ -994,11 +994,8 @@ void reprepare_packed_git(struct repository *r)
994 {
995 struct object_directory *odb;
996
997 - for (odb = r->objects->odb; odb; odb = odb->next) {
998 - oid_array_clear(&odb->loose_objects_cache);
999 - memset(&odb->loose_objects_subdir_seen, 0,
1000 - sizeof(odb->loose_objects_subdir_seen));
1001 - }
997 + for (odb = r->objects->odb; odb; odb = odb->next)
998 + odb_clear_loose_cache(odb);
999
1000 r->objects->approximate_object_count_valid = 0;
1001 r->objects->packed_git_initialized = 0;
sha1-file.c
+7
@@ -2178,6 +2178,13 @@ void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
2178 strbuf_release(&buf);
2179 }
2180
2181 +void odb_clear_loose_cache(struct object_directory *odb)
2182 +{
2183 + oid_array_clear(&odb->loose_objects_cache);
2184 + memset(&odb->loose_objects_subdir_seen, 0,
2185 + sizeof(odb->loose_objects_subdir_seen));
2186 +}
2187 +
2188 static int check_stream_sha1(git_zstream *stream,
2189 const char *hdr,
2190 unsigned long size,