summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-06-22 18:19:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-22 19:07:51 (GMT)
commitcc817ca3ef2267c21af9589a7f92190a3659906c (patch)
treedf2fef1adc0a4c45d9d7a3275a6aff2081b9e52e /cache.h
parentfd99e2bda0ca6a361ef03c04d6d7fdc7a9c40b78 (diff)
downloadgit-cc817ca3ef2267c21af9589a7f92190a3659906c.zip
git-cc817ca3ef2267c21af9589a7f92190a3659906c.tar.gz
git-cc817ca3ef2267c21af9589a7f92190a3659906c.tar.bz2
sha1_name: cache readdir(3) results in find_short_object_filename()
Read each loose object subdirectory at most once when looking for unique abbreviated hashes. This speeds up commands like "git log --pretty=%h" considerably, which previously caused one readdir(3) call for each candidate, even for subdirectories that were visited before. The new cache is kept until the program ends and never invalidated. The same is already true for pack indexes. The inherent racy nature of finding unique short hashes makes it still fit for this purpose -- a conflicting new object may be added at any time. Tasks with higher consistency requirements should not use it, though. The cached object names are stored in an oid_array, which is quite compact. The bitmap for remembering which subdir was already read is stored as a char array, with one char per directory -- that's not quite as compact, but really simple and incurs only an overhead equivalent to 11 hashes after all. Suggested-by: Jeff King <peff@peff.net> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index e1f0e18..1ad9140 100644
--- a/cache.h
+++ b/cache.h
@@ -11,6 +11,7 @@
#include "string-list.h"
#include "pack-revindex.h"
#include "hash.h"
+#include "sha1-array.h"
#ifndef platform_SHA_CTX
/*
@@ -1579,6 +1580,16 @@ extern struct alternate_object_database {
struct strbuf scratch;
size_t base_len;
+ /*
+ * Used to store the results of readdir(3) calls when searching
+ * for unique abbreviated hashes. This cache is never
+ * invalidated, thus it's racy and not necessarily accurate.
+ * That's fine for its purpose; don't use it for tasks requiring
+ * greater accuracy!
+ */
+ char loose_objects_subdir_seen[256];
+ struct oid_array loose_objects_cache;
+
char path[FLEX_ARRAY];
} *alt_odb_list;
extern void prepare_alt_odb(void);
@@ -1797,6 +1808,12 @@ typedef int each_loose_cruft_fn(const char *basename,
typedef int each_loose_subdir_fn(int nr,
const char *path,
void *data);
+int for_each_file_in_obj_subdir(int subdir_nr,
+ struct strbuf *path,
+ each_loose_object_fn obj_cb,
+ each_loose_cruft_fn cruft_cb,
+ each_loose_subdir_fn subdir_cb,
+ void *data);
int for_each_loose_file_in_objdir(const char *path,
each_loose_object_fn obj_cb,
each_loose_cruft_fn cruft_cb,