summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-07-05 20:32:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-07-05 20:32:56 (GMT)
commit5ab148dda0076a136b4afb385d96bd9cdc4d2590 (patch)
tree6e6876952e2e6a1154258c9a9e11428572d4dcf9 /sha1_file.c
parent85ce4a6828a418a22c69a870b3e059481b4263d6 (diff)
parent70c49050d4a16a7e2990e4d3c91d9d12f62e631e (diff)
downloadgit-5ab148dda0076a136b4afb385d96bd9cdc4d2590.zip
git-5ab148dda0076a136b4afb385d96bd9cdc4d2590.tar.gz
git-5ab148dda0076a136b4afb385d96bd9cdc4d2590.tar.bz2
Merge branch 'rs/sha1-name-readdir-optim'
Optimize "what are the object names already taken in an alternate object database?" query that is used to derive the length of prefix an object name is uniquely abbreviated to. * rs/sha1-name-readdir-optim: sha1_file: guard against invalid loose subdirectory numbers sha1_file: let for_each_file_in_obj_subdir() handle subdir names p4205: add perf test script for pretty log formats sha1_name: cache readdir(3) results in find_short_object_filename()
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/sha1_file.c b/sha1_file.c
index fb1fd80..9a9f7f7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3735,22 +3735,32 @@ void assert_sha1_type(const unsigned char *sha1, enum object_type expect)
typename(expect));
}
-static 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)
-{
- size_t baselen = path->len;
- DIR *dir = opendir(path->buf);
+int for_each_file_in_obj_subdir(unsigned 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)
+{
+ size_t origlen, baselen;
+ DIR *dir;
struct dirent *de;
int r = 0;
+ if (subdir_nr > 0xff)
+ BUG("invalid loose object subdirectory: %x", subdir_nr);
+
+ origlen = path->len;
+ strbuf_complete(path, '/');
+ strbuf_addf(path, "%02x", subdir_nr);
+ baselen = path->len;
+
+ dir = opendir(path->buf);
if (!dir) {
- if (errno == ENOENT)
- return 0;
- return error_errno("unable to open %s", path->buf);
+ if (errno != ENOENT)
+ r = error_errno("unable to open %s", path->buf);
+ strbuf_setlen(path, origlen);
+ return r;
}
while ((de = readdir(dir))) {
@@ -3788,6 +3798,8 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
if (!r && subdir_cb)
r = subdir_cb(subdir_nr, path->buf, data);
+ strbuf_setlen(path, origlen);
+
return r;
}
@@ -3797,15 +3809,12 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
each_loose_subdir_fn subdir_cb,
void *data)
{
- size_t baselen = path->len;
int r = 0;
int i;
for (i = 0; i < 256; i++) {
- strbuf_addf(path, "/%02x", i);
r = for_each_file_in_obj_subdir(i, path, obj_cb, cruft_cb,
subdir_cb, data);
- strbuf_setlen(path, baselen);
if (r)
break;
}