summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-12 14:50:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 05:22:03 (GMT)
commit3a2e08245cfccd932bb3ff78521e07d4a38c2834 (patch)
treeeedf38839cf088ba390bfe12230bccaf5885427d /sha1-file.c
parentf0eaf638195a6510254b075026dcad955b8b607d (diff)
downloadgit-3a2e08245cfccd932bb3ff78521e07d4a38c2834.zip
git-3a2e08245cfccd932bb3ff78521e07d4a38c2834.tar.gz
git-3a2e08245cfccd932bb3ff78521e07d4a38c2834.tar.bz2
object-store: provide helpers for loose_objects_cache
Our object_directory struct has a loose objects cache that all users of the struct can see. But the only one that knows how to load the cache is find_short_object_filename(). Let's extract that logic in to a reusable function. While we're at it, let's also reset the cache when we re-read the object directories. This shouldn't have an impact on performance, as re-reads are meant to be rare (and are already expensive, so we avoid them with things like OBJECT_INFO_QUICK). Since the cache is already meant to be an approximation, it's tempting to skip even this bit of safety. But it's necessary to allow more code to use it. For instance, fetch-pack explicitly re-reads the object directory after performing its fetch, and would be confused if we didn't clear the cache. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 503262e..4aae716 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -2125,6 +2125,32 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
return 0;
}
+static int append_loose_object(const struct object_id *oid, const char *path,
+ void *data)
+{
+ oid_array_append(data, oid);
+ return 0;
+}
+
+void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ if (subdir_nr < 0 ||
+ subdir_nr >= ARRAY_SIZE(odb->loose_objects_subdir_seen))
+ BUG("subdir_nr out of range");
+
+ if (odb->loose_objects_subdir_seen[subdir_nr])
+ return;
+
+ strbuf_addstr(&buf, odb->path);
+ for_each_file_in_obj_subdir(subdir_nr, &buf,
+ append_loose_object,
+ NULL, NULL,
+ &odb->loose_objects_cache);
+ odb->loose_objects_subdir_seen[subdir_nr] = 1;
+}
+
static int check_stream_sha1(git_zstream *stream,
const char *hdr,
unsigned long size,