Skip to content

Commit 161d8a1

Browse files
committed
sha256: wrap_odb supports SHA256
1 parent f1ef8eb commit 161d8a1

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

include/git2/repository.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,19 @@ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_work
5656
*
5757
* @param out pointer to the repo
5858
* @param odb the object database to wrap
59+
* @param oid_type the oid type of the object database
5960
* @return 0 or an error code
6061
*/
61-
GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
62+
#ifdef GIT_EXPERIMENTAL_SHA256
63+
GIT_EXTERN(int) git_repository_wrap_odb(
64+
git_repository **out,
65+
git_odb *odb,
66+
git_oid_t oid_type);
67+
#else
68+
GIT_EXTERN(int) git_repository_wrap_odb(
69+
git_repository **out,
70+
git_odb *odb);
71+
#endif
6272

6373
/**
6474
* Look for a git repository and copy its path in the given buffer.
@@ -536,7 +546,7 @@ GIT_EXTERN(const char *) git_repository_workdir(const git_repository *repo);
536546

537547
/**
538548
* Get the path of the shared common directory for this repository.
539-
*
549+
*
540550
* If the repository is bare, it is the root directory for the repository.
541551
* If the repository is a worktree, it is the parent repo's gitdir.
542552
* Otherwise, it is the gitdir.

src/libgit2/repository.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,21 +1145,39 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
11451145
return err;
11461146
}
11471147

1148-
int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb)
1148+
int git_repository__wrap_odb(
1149+
git_repository **out,
1150+
git_odb *odb,
1151+
git_oid_t oid_type)
11491152
{
11501153
git_repository *repo;
11511154

11521155
repo = repository_alloc();
11531156
GIT_ERROR_CHECK_ALLOC(repo);
11541157

1155-
repo->oid_type = GIT_OID_DEFAULT;
1158+
repo->oid_type = oid_type;
11561159

11571160
git_repository_set_odb(repo, odb);
1158-
*repo_out = repo;
1161+
*out = repo;
11591162

11601163
return 0;
11611164
}
11621165

1166+
#ifdef GIT_EXPERIMENTAL_SHA256
1167+
int git_repository_wrap_odb(
1168+
git_repository **out,
1169+
git_odb *odb,
1170+
git_oid_t oid_type)
1171+
{
1172+
return git_repository__wrap_odb(out, odb, oid_type);
1173+
}
1174+
#else
1175+
int git_repository_wrap_odb(git_repository **out, git_odb *odb)
1176+
{
1177+
return git_repository__wrap_odb(out, odb, GIT_OID_DEFAULT);
1178+
}
1179+
#endif
1180+
11631181
int git_repository_discover(
11641182
git_buf *out,
11651183
const char *start_path,

src/libgit2/repository.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
190190
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
191191
int git_repository_index__weakptr(git_index **out, git_repository *repo);
192192

193+
int git_repository__wrap_odb(
194+
git_repository **out,
195+
git_odb *odb,
196+
git_oid_t oid_type);
197+
193198
/*
194199
* Configuration map cache
195200
*

tests/libgit2/odb/backend/loose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void test_odb_backend_loose__initialize(void)
2121

2222
cl_git_pass(git_odb__new(&_odb, NULL));
2323
cl_git_pass(git_odb_add_backend(_odb, backend, 10));
24-
cl_git_pass(git_repository_wrap_odb(&_repo, _odb));
24+
cl_git_pass(git_repository__wrap_odb(&_repo, _odb, GIT_OID_SHA1));
2525
}
2626

2727
void test_odb_backend_loose__cleanup(void)

tests/libgit2/odb/backend/mempack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void test_odb_backend_mempack__initialize(void)
1616
cl_git_pass(git_mempack_new(&backend));
1717
cl_git_pass(git_odb__new(&_odb, NULL));
1818
cl_git_pass(git_odb_add_backend(_odb, backend, 10));
19-
cl_git_pass(git_repository_wrap_odb(&_repo, _odb));
19+
cl_git_pass(git_repository__wrap_odb(&_repo, _odb, GIT_OID_SHA1));
2020
}
2121

2222
void test_odb_backend_mempack__cleanup(void)

tests/libgit2/refs/iterator.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "refs.h"
33
#include "vector.h"
44
#include "odb.h"
5+
#include "repository.h"
56

67
static git_repository *repo;
78

@@ -128,7 +129,7 @@ void test_refs_iterator__empty(void)
128129
git_repository *empty;
129130

130131
cl_git_pass(git_odb__new(&odb, NULL));
131-
cl_git_pass(git_repository_wrap_odb(&empty, odb));
132+
cl_git_pass(git_repository__wrap_odb(&empty, odb, GIT_OID_SHA1));
132133

133134
cl_git_pass(git_reference_iterator_new(&iter, empty));
134135
cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter));

0 commit comments

Comments
 (0)