Skip to content

Commit af12fc1

Browse files
authored
Merge pull request libgit2#6520 from libgit2/ethomson/git_odb_open
odb: restore `git_odb_open`
2 parents 7445d51 + e1e0d77 commit af12fc1

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/libgit2/odb.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,25 @@ int git_odb__open(
856856
return 0;
857857
}
858858

859+
#ifdef GIT_EXPERIMENTAL_SHA256
860+
861+
int git_odb_open(
862+
git_odb **out,
863+
const char *objects_dir,
864+
const git_odb_options *opts)
865+
{
866+
return git_odb__open(out, objects_dir, opts);
867+
}
868+
869+
#else
870+
871+
int git_odb_open(git_odb **out, const char *objects_dir)
872+
{
873+
return git_odb__open(out, objects_dir, NULL);
874+
}
875+
876+
#endif
877+
859878
int git_odb__set_caps(git_odb *odb, int caps)
860879
{
861880
if (caps == GIT_ODB_CAP_FROM_OWNER) {

tests/libgit2/odb/open.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "clar_libgit2.h"
2+
3+
void test_odb_open__initialize(void)
4+
{
5+
cl_fixture_sandbox("testrepo.git");
6+
}
7+
8+
void test_odb_open__cleanup(void)
9+
{
10+
cl_fixture_cleanup("testrepo.git");
11+
}
12+
13+
void test_odb_open__exists(void)
14+
{
15+
git_odb *odb;
16+
git_oid one, two;
17+
18+
#ifdef GIT_EXPERIMENTAL_SHA256
19+
git_odb_options opts = GIT_ODB_OPTIONS_INIT;
20+
21+
cl_git_pass(git_odb_open(&odb, "testrepo.git/objects", &opts));
22+
cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1));
23+
cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233", GIT_OID_SHA1));
24+
#else
25+
cl_git_pass(git_odb_open(&odb, "testrepo.git/objects"));
26+
cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
27+
cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233"));
28+
#endif
29+
30+
cl_assert(git_odb_exists(odb, &one));
31+
cl_assert(!git_odb_exists(odb, &two));
32+
33+
git_odb_free(odb);
34+
}

0 commit comments

Comments
 (0)