summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-07-08 17:17:09 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 21:26:12 +0000
commit479c8c8c14f83491f31fb9b23388ae17070c9549 (patch)
tree9847977931b5c77325c11cc4ed79163db870fe56 /tests
parente89e2e0102300af1faf0ab892e598a700692718a (diff)
downloadlibgit2-479c8c8c14f83491f31fb9b23388ae17070c9549.tar.gz
packfile: handle sha256 packfiles
Teach the packfile machinery to cope with SHA256.
Diffstat (limited to 'tests')
-rw-r--r--tests/libgit2/odb/foreach.c11
-rw-r--r--tests/libgit2/odb/pack_data_one256.h21
-rw-r--r--tests/libgit2/odb/packedone.c9
-rw-r--r--tests/libgit2/odb/packedone256.c78
-rw-r--r--tests/libgit2/odb/sorting.c6
-rw-r--r--tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idxbin0 -> 1376 bytes
-rw-r--r--tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.packbin0 -> 1406 bytes
7 files changed, 122 insertions, 3 deletions
diff --git a/tests/libgit2/odb/foreach.c b/tests/libgit2/odb/foreach.c
index 165a511a0..56b3e882c 100644
--- a/tests/libgit2/odb/foreach.c
+++ b/tests/libgit2/odb/foreach.c
@@ -52,7 +52,16 @@ void test_odb_foreach__one_pack(void)
int nobj = 0;
cl_git_pass(git_odb__new(&_odb, NULL));
- cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_odb_backend_one_pack(&backend,
+ cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"),
+ NULL));
+#else
+ cl_git_pass(git_odb_backend_one_pack(&backend,
+ cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+#endif
+
cl_git_pass(git_odb_add_backend(_odb, backend, 1));
_repo = NULL;
diff --git a/tests/libgit2/odb/pack_data_one256.h b/tests/libgit2/odb/pack_data_one256.h
new file mode 100644
index 000000000..98a874798
--- /dev/null
+++ b/tests/libgit2/odb/pack_data_one256.h
@@ -0,0 +1,21 @@
+/* Just a few to make sure it's working, the rest is tested already */
+#ifdef GIT_EXPERIMENTAL_SHA256
+static const char *packed_objects_one256[] = {
+ "ea926306b1bab6d3f25f45609907eb6dff91a1460b25e63bf4a0494c70e7a269",
+ "d048ba2ef4fafa502a44cbc1a50cd58359b9bc243b84a08f541a08ca5f621137",
+ "a66bda0109d2b3c9bc87970da81bd91076b5f871febbc860f09ae997668b6800",
+ "3609a41c0506fe19d01fb8b4729923362675f191fe5f63fab3111ef804c48fdf",
+ "22b6705b86e4aa9120eff203af24709d483698d9f78695e86e82de121784b570",
+ "6f11d93bfb269ee8c7a506178f60c430abfac5d424acfd9c0b0b27b98e6ab49b",
+ "0aefd477d9e5b3f8d708a3cf6d78be6b670dfa2e2ec41244634f3b8f115d8e04",
+ "580474d948cd2ebd2e5ce7a5b81b872d87ba4639c1ac4c0fa7a11a8eddf9827c",
+ "0636b4292bfdd7274a977cb6f8b2ded8f315ea1bcd8dbedfca37964c2ed3d085",
+ "19fb1c78b11f0f8bda658d6fa6cc63c0b573c0f6760ee5a9c2df6ce2cde00c5c",
+ "7f2f7afccb317bb3fdd28555f126846dc4eebe5d9ae7b8d8a1456e8ff85422ce",
+ "4066249c68b0d3c8b39ebe02c9188935900465acad02a49269710f56720fa58e",
+ "a560d1fa1edf114f57b402e16d662c17b1e3b7e8601ff7dcea6615ba7f1e48ef",
+ "58923faa87c7d559d308a114ec2b164e5d6046c889420ed1def6eef2d55106a2",
+ "753ddabab8ae9c1e733cda15e8e3c83dd43f5a2d939ae32cc3b30b0be1e91f96",
+ "46333d32b3801cf11d9f80b557245c9e32b0e05deca61dae968914fde159f0e5"
+};
+#endif
diff --git a/tests/libgit2/odb/packedone.c b/tests/libgit2/odb/packedone.c
index 9af27e8c7..8637001ff 100644
--- a/tests/libgit2/odb/packedone.c
+++ b/tests/libgit2/odb/packedone.c
@@ -11,7 +11,14 @@ void test_odb_packedone__initialize(void)
git_odb_backend *backend = NULL;
cl_git_pass(git_odb__new(&_odb, NULL));
- cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_odb_backend_one_pack(&backend,
+ cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"),
+ NULL));
+#else
+ cl_git_pass(git_odb_backend_one_pack(&backend,
+ cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
+#endif
cl_git_pass(git_odb_add_backend(_odb, backend, 1));
}
diff --git a/tests/libgit2/odb/packedone256.c b/tests/libgit2/odb/packedone256.c
new file mode 100644
index 000000000..fdeac4205
--- /dev/null
+++ b/tests/libgit2/odb/packedone256.c
@@ -0,0 +1,78 @@
+#include "clar_libgit2.h"
+#include "git2/odb_backend.h"
+
+#include "pack_data_one256.h"
+#include "pack.h"
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+static git_odb *_odb;
+#endif
+
+void test_odb_packedone256__initialize(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_odb_backend *backend = NULL;
+ git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
+ git_odb_backend_pack_options backend_opts = GIT_ODB_BACKEND_PACK_OPTIONS_INIT;
+
+ odb_opts.oid_type = GIT_OID_SHA256;
+ backend_opts.oid_type = GIT_OID_SHA256;
+
+ cl_git_pass(git_odb__new(&_odb, &odb_opts));
+ cl_git_pass(git_odb_backend_one_pack(
+ &backend,
+ cl_fixture("testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx"),
+ &backend_opts));
+ cl_git_pass(git_odb_add_backend(_odb, backend, 1));
+#endif
+}
+
+void test_odb_packedone256__cleanup(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_odb_free(_odb);
+ _odb = NULL;
+#endif
+}
+
+void test_odb_packedone256__mass_read(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) {
+ git_oid id;
+ git_odb_object *obj;
+
+ cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256));
+ cl_assert(git_odb_exists(_odb, &id) == 1);
+ cl_git_pass(git_odb_read(&obj, _odb, &id));
+
+ git_odb_object_free(obj);
+ }
+#endif
+}
+
+void test_odb_packedone256__read_header_0(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) {
+ git_oid id;
+ git_odb_object *obj;
+ size_t len;
+ git_object_t type;
+
+ cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256));
+
+ cl_git_pass(git_odb_read(&obj, _odb, &id));
+ cl_git_pass(git_odb_read_header(&len, &type, _odb, &id));
+
+ cl_assert(obj->cached.size == len);
+ cl_assert(obj->cached.type == type);
+
+ git_odb_object_free(obj);
+ }
+#endif
+}
diff --git a/tests/libgit2/odb/sorting.c b/tests/libgit2/odb/sorting.c
index 1010872f4..ec4e3696b 100644
--- a/tests/libgit2/odb/sorting.c
+++ b/tests/libgit2/odb/sorting.c
@@ -82,7 +82,11 @@ void test_odb_sorting__override_default_backend_priority(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_LOOSE_PRIORITY, 5));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_PACKED_PRIORITY, 3));
- git_odb_backend_pack(&packed, "./testrepo.git/objects");
+ git_odb_backend_pack(&packed, "./testrepo.git/objects"
+#ifdef GIT_EXPERIMENTAL_SHA256
+ , NULL
+#endif
+ );
git_odb__backend_loose(&loose, "./testrepo.git/objects", NULL);
cl_git_pass(git_odb__open(&new_odb, cl_fixture("testrepo.git/objects"), NULL));
diff --git a/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx
new file mode 100644
index 000000000..7aa472cea
--- /dev/null
+++ b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx
Binary files differ
diff --git a/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack
new file mode 100644
index 000000000..adbe70ad3
--- /dev/null
+++ b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack
Binary files differ