Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 731af14

Browse files
committed
repo: add oid type support to git_repository_new
1 parent b49b8db commit 731af14

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

include/git2/sys/repository.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "git2/common.h"
1111
#include "git2/types.h"
12+
#include "git2/oid.h"
1213

1314
/**
1415
* @file git2/sys/repository.h
@@ -32,7 +33,11 @@ GIT_BEGIN_DECL
3233
* @param out The blank repository
3334
* @return 0 on success, or an error code
3435
*/
36+
#ifdef GIT_EXPERIMENTAL_SHA256
37+
GIT_EXTERN(int) git_repository_new(git_repository **out, git_oid_t oid_type);
38+
#else
3539
GIT_EXTERN(int) git_repository_new(git_repository **out);
40+
#endif
3641

3742
/**
3843
* Reset all the internal state in a repository.

src/libgit2/repository.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static git_repository *repository_alloc(void)
328328
return NULL;
329329
}
330330

331-
int git_repository_new(git_repository **out)
331+
int git_repository__new(git_repository **out, git_oid_t oid_type)
332332
{
333333
git_repository *repo;
334334

@@ -337,10 +337,23 @@ int git_repository_new(git_repository **out)
337337

338338
repo->is_bare = 1;
339339
repo->is_worktree = 0;
340+
repo->oid_type = oid_type;
340341

341342
return 0;
342343
}
343344

345+
#ifdef GIT_EXPERIMENTAL_SHA256
346+
int git_repository_new(git_repository **out, git_oid_t oid_type)
347+
{
348+
return git_repository__new(out, oid_type);
349+
}
350+
#else
351+
int git_repository_new(git_repository** out)
352+
{
353+
return git_repository__new(out, GIT_OID_SHA1);
354+
}
355+
#endif
356+
344357
static int load_config_data(git_repository *repo, const git_config *config)
345358
{
346359
int is_bare;

src/libgit2/repository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,7 @@ int git_repository__set_objectformat(
280280
git_repository *repo,
281281
git_oid_t oid_type);
282282

283+
/* SHA256-aware internal functions */
284+
int git_repository__new(git_repository **out, git_oid_t oid_type);
285+
283286
#endif

tests/libgit2/network/remote/local.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,11 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
473473

474474
git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));
475475

476+
#ifdef GIT_EXPERIMENTAL_SHA256
477+
cl_git_pass(git_repository_new(&inmemory, GIT_OID_SHA1));
478+
#else
476479
cl_git_pass(git_repository_new(&inmemory));
480+
#endif
477481
cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_str_cstr(&file_path_buf)));
478482
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
479483
cl_assert(git_remote_connected(remote));

tests/libgit2/odb/backend/nobackend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ void test_odb_backend_nobackend__initialize(void)
1111
git_odb *odb;
1212
git_refdb *refdb;
1313

14+
#ifdef GIT_EXPERIMENTAL_SHA256
15+
cl_git_pass(git_repository_new(&_repo, GIT_OID_SHA1));
16+
#else
1417
cl_git_pass(git_repository_new(&_repo));
18+
#endif
1519
cl_git_pass(git_config_new(&config));
1620
cl_git_pass(git_odb__new(&odb, NULL));
1721
cl_git_pass(git_refdb_new(&refdb, _repo));

tests/libgit2/repo/new.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ void test_repo_new__has_nothing(void)
55
{
66
git_repository *repo;
77

8+
#ifdef GIT_EXPERIMENTAL_SHA256
9+
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
10+
#else
811
cl_git_pass(git_repository_new(&repo));
12+
#endif
913
cl_assert_equal_b(true, git_repository_is_bare(repo));
1014
cl_assert_equal_p(NULL, git_repository_path(repo));
1115
cl_assert_equal_p(NULL, git_repository_workdir(repo));
@@ -16,7 +20,11 @@ void test_repo_new__is_bare_until_workdir_set(void)
1620
{
1721
git_repository *repo;
1822

23+
#ifdef GIT_EXPERIMENTAL_SHA256
24+
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
25+
#else
1926
cl_git_pass(git_repository_new(&repo));
27+
#endif
2028
cl_assert_equal_b(true, git_repository_is_bare(repo));
2129

2230
cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
@@ -25,3 +33,30 @@ void test_repo_new__is_bare_until_workdir_set(void)
2533
git_repository_free(repo);
2634
}
2735

36+
void test_repo_new__sha1(void)
37+
{
38+
git_repository *repo;
39+
40+
#ifdef GIT_EXPERIMENTAL_SHA256
41+
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
42+
#else
43+
cl_git_pass(git_repository_new(&repo));
44+
#endif
45+
cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(repo));
46+
47+
git_repository_free(repo);
48+
}
49+
50+
void test_repo_new__sha256(void)
51+
{
52+
#ifndef GIT_EXPERIMENTAL_SHA256
53+
cl_skip();
54+
#else
55+
git_repository *repo;
56+
57+
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA256));
58+
cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(repo));
59+
60+
git_repository_free(repo);
61+
#endif
62+
}

0 commit comments

Comments
 (0)