summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorColin Stolley <ccstolley@github.com>2021-10-07 13:26:52 -0500
committerColin Stolley <ccstolley@github.com>2021-12-14 10:07:03 -0600
commitad7a51d83496cb6f2bb7b08a426f832f589c7707 (patch)
tree3c967c1b268fc1fb9d5997f384ec1012837c59c6 /tests
parent12b53eb0318b0529514ad7e318de70b8325d43f2 (diff)
downloadlibgit2-ad7a51d83496cb6f2bb7b08a426f832f589c7707.tar.gz
refs: Speed up packed lookups.
Currently ref lookups require loading the entire packed-refs file into a hashmap in memory. For repos with large numbers of refs this can be painfully slow. This patch replaces the existing lookup code and instead mmap()'s the packed-refs file and performs a binary search to locate the ref entry. Git uses a similiar approach. The old hash table codepath is still used for unsorted packed-refs files. This patch also fixes a minor bug where the "peeled" trait is never parsed correctly from the packed-refs header.
Diffstat (limited to 'tests')
-rw-r--r--tests/refs/crashes.c24
-rw-r--r--tests/resources/peeled.git/packed-refs2
-rw-r--r--tests/resources/testrepo.git/packed-refs2
-rw-r--r--tests/resources/testrepo/.gitted/packed-refs2
-rw-r--r--tests/resources/testrepo2/.gitted/packed-refs2
5 files changed, 28 insertions, 4 deletions
diff --git a/tests/refs/crashes.c b/tests/refs/crashes.c
index 228f479a0..4f508aed2 100644
--- a/tests/refs/crashes.c
+++ b/tests/refs/crashes.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "refs.h"
void test_refs_crashes__double_free(void)
{
@@ -18,3 +19,26 @@ void test_refs_crashes__double_free(void)
cl_git_sandbox_cleanup();
}
+
+void test_refs_crashes__empty_packedrefs(void)
+{
+ git_repository *repo;
+ git_reference *ref;
+ const char *REFNAME = "refs/heads/xxx";
+ git_str temp_path = GIT_STR_INIT;
+ int fd = 0;
+
+ repo = cl_git_sandbox_init("empty_bare.git");
+
+ /* create zero-length packed-refs file */
+ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(repo), GIT_PACKEDREFS_FILE));
+ cl_git_pass(((fd = p_creat(temp_path.ptr, 0644)) < 0));
+ cl_git_pass(p_close(fd));
+
+ /* should fail gracefully */
+ cl_git_fail_with(
+ GIT_ENOTFOUND, git_reference_lookup(&ref, repo, REFNAME));
+
+ cl_git_sandbox_cleanup();
+ git_str_dispose(&temp_path);
+}
diff --git a/tests/resources/peeled.git/packed-refs b/tests/resources/peeled.git/packed-refs
index ad053d550..078f237ed 100644
--- a/tests/resources/peeled.git/packed-refs
+++ b/tests/resources/peeled.git/packed-refs
@@ -1,4 +1,4 @@
-# pack-refs with: peeled fully-peeled
+# pack-refs with: peeled fully-peeled sorted
c2596aa0151888587ec5c0187f261e63412d9e11 refs/foo/tag-outside-tags
^0df1a5865c8abfc09f1f2182e6a31be550e99f07
0df1a5865c8abfc09f1f2182e6a31be550e99f07 refs/heads/master
diff --git a/tests/resources/testrepo.git/packed-refs b/tests/resources/testrepo.git/packed-refs
index 52f5e876f..fadd7e88a 100644
--- a/tests/resources/testrepo.git/packed-refs
+++ b/tests/resources/testrepo.git/packed-refs
@@ -1,3 +1,3 @@
-# pack-refs with: peeled
+# pack-refs with: peeled sorted
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/heads/packed
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/heads/packed-test
diff --git a/tests/resources/testrepo/.gitted/packed-refs b/tests/resources/testrepo/.gitted/packed-refs
index 6018a19d2..b57898695 100644
--- a/tests/resources/testrepo/.gitted/packed-refs
+++ b/tests/resources/testrepo/.gitted/packed-refs
@@ -1,4 +1,4 @@
-# pack-refs with: peeled
+# pack-refs with: peeled sorted
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/heads/packed
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/heads/packed-test
b25fa35b38051e4ae45d4222e795f9df2e43f1d1 refs/tags/packed-tag
diff --git a/tests/resources/testrepo2/.gitted/packed-refs b/tests/resources/testrepo2/.gitted/packed-refs
index 97ea6a848..01de87173 100644
--- a/tests/resources/testrepo2/.gitted/packed-refs
+++ b/tests/resources/testrepo2/.gitted/packed-refs
@@ -1,4 +1,4 @@
-# pack-refs with: peeled fully-peeled
+# pack-refs with: peeled fully-peeled sorted
36060c58702ed4c2a40832c51758d5344201d89a refs/remotes/origin/master
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/remotes/origin/packed
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/tags/v0.9