Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e020c85e
Unverified
Commit
e020c85e
authored
Dec 14, 2023
by
Edward Thomson
Committed by
GitHub
Dec 14, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6671 from kcsaul/repo_new_oid_type
Support setting oid type for in-memory repositories
parents
2dbc810a
731af14b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
1 deletions
+65
-1
include/git2/sys/repository.h
+5
-0
src/libgit2/repository.c
+14
-1
src/libgit2/repository.h
+3
-0
tests/libgit2/network/remote/local.c
+4
-0
tests/libgit2/odb/backend/nobackend.c
+4
-0
tests/libgit2/repo/new.c
+35
-0
No files found.
include/git2/sys/repository.h
View file @
e020c85e
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include "git2/common.h"
#include "git2/common.h"
#include "git2/types.h"
#include "git2/types.h"
#include "git2/oid.h"
/**
/**
* @file git2/sys/repository.h
* @file git2/sys/repository.h
...
@@ -32,7 +33,11 @@ GIT_BEGIN_DECL
...
@@ -32,7 +33,11 @@ GIT_BEGIN_DECL
* @param out The blank repository
* @param out The blank repository
* @return 0 on success, or an error code
* @return 0 on success, or an error code
*/
*/
#ifdef GIT_EXPERIMENTAL_SHA256
GIT_EXTERN
(
int
)
git_repository_new
(
git_repository
**
out
,
git_oid_t
oid_type
);
#else
GIT_EXTERN
(
int
)
git_repository_new
(
git_repository
**
out
);
GIT_EXTERN
(
int
)
git_repository_new
(
git_repository
**
out
);
#endif
/**
/**
* Reset all the internal state in a repository.
* Reset all the internal state in a repository.
...
...
src/libgit2/repository.c
View file @
e020c85e
...
@@ -328,7 +328,7 @@ on_error:
...
@@ -328,7 +328,7 @@ on_error:
return
NULL
;
return
NULL
;
}
}
int
git_repository_
new
(
git_repository
**
out
)
int
git_repository_
_new
(
git_repository
**
out
,
git_oid_t
oid_type
)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
...
@@ -337,10 +337,23 @@ int git_repository_new(git_repository **out)
...
@@ -337,10 +337,23 @@ int git_repository_new(git_repository **out)
repo
->
is_bare
=
1
;
repo
->
is_bare
=
1
;
repo
->
is_worktree
=
0
;
repo
->
is_worktree
=
0
;
repo
->
oid_type
=
oid_type
;
return
0
;
return
0
;
}
}
#ifdef GIT_EXPERIMENTAL_SHA256
int
git_repository_new
(
git_repository
**
out
,
git_oid_t
oid_type
)
{
return
git_repository__new
(
out
,
oid_type
);
}
#else
int
git_repository_new
(
git_repository
**
out
)
{
return
git_repository__new
(
out
,
GIT_OID_SHA1
);
}
#endif
static
int
load_config_data
(
git_repository
*
repo
,
const
git_config
*
config
)
static
int
load_config_data
(
git_repository
*
repo
,
const
git_config
*
config
)
{
{
int
is_bare
;
int
is_bare
;
...
...
src/libgit2/repository.h
View file @
e020c85e
...
@@ -280,4 +280,7 @@ int git_repository__set_objectformat(
...
@@ -280,4 +280,7 @@ int git_repository__set_objectformat(
git_repository
*
repo
,
git_repository
*
repo
,
git_oid_t
oid_type
);
git_oid_t
oid_type
);
/* SHA256-aware internal functions */
int
git_repository__new
(
git_repository
**
out
,
git_oid_t
oid_type
);
#endif
#endif
tests/libgit2/network/remote/local.c
View file @
e020c85e
...
@@ -473,7 +473,11 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
...
@@ -473,7 +473,11 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
git_str_sets
(
&
file_path_buf
,
cl_git_path_url
(
cl_fixture
(
"testrepo.git"
)));
git_str_sets
(
&
file_path_buf
,
cl_git_path_url
(
cl_fixture
(
"testrepo.git"
)));
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass
(
git_repository_new
(
&
inmemory
,
GIT_OID_SHA1
));
#else
cl_git_pass
(
git_repository_new
(
&
inmemory
));
cl_git_pass
(
git_repository_new
(
&
inmemory
));
#endif
cl_git_pass
(
git_remote_create_anonymous
(
&
remote
,
inmemory
,
git_str_cstr
(
&
file_path_buf
)));
cl_git_pass
(
git_remote_create_anonymous
(
&
remote
,
inmemory
,
git_str_cstr
(
&
file_path_buf
)));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
,
NULL
));
cl_assert
(
git_remote_connected
(
remote
));
cl_assert
(
git_remote_connected
(
remote
));
...
...
tests/libgit2/odb/backend/nobackend.c
View file @
e020c85e
...
@@ -11,7 +11,11 @@ void test_odb_backend_nobackend__initialize(void)
...
@@ -11,7 +11,11 @@ void test_odb_backend_nobackend__initialize(void)
git_odb
*
odb
;
git_odb
*
odb
;
git_refdb
*
refdb
;
git_refdb
*
refdb
;
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass
(
git_repository_new
(
&
_repo
,
GIT_OID_SHA1
));
#else
cl_git_pass
(
git_repository_new
(
&
_repo
));
cl_git_pass
(
git_repository_new
(
&
_repo
));
#endif
cl_git_pass
(
git_config_new
(
&
config
));
cl_git_pass
(
git_config_new
(
&
config
));
cl_git_pass
(
git_odb__new
(
&
odb
,
NULL
));
cl_git_pass
(
git_odb__new
(
&
odb
,
NULL
));
cl_git_pass
(
git_refdb_new
(
&
refdb
,
_repo
));
cl_git_pass
(
git_refdb_new
(
&
refdb
,
_repo
));
...
...
tests/libgit2/repo/new.c
View file @
e020c85e
...
@@ -5,7 +5,11 @@ void test_repo_new__has_nothing(void)
...
@@ -5,7 +5,11 @@ void test_repo_new__has_nothing(void)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass
(
git_repository_new
(
&
repo
,
GIT_OID_SHA1
));
#else
cl_git_pass
(
git_repository_new
(
&
repo
));
cl_git_pass
(
git_repository_new
(
&
repo
));
#endif
cl_assert_equal_b
(
true
,
git_repository_is_bare
(
repo
));
cl_assert_equal_b
(
true
,
git_repository_is_bare
(
repo
));
cl_assert_equal_p
(
NULL
,
git_repository_path
(
repo
));
cl_assert_equal_p
(
NULL
,
git_repository_path
(
repo
));
cl_assert_equal_p
(
NULL
,
git_repository_workdir
(
repo
));
cl_assert_equal_p
(
NULL
,
git_repository_workdir
(
repo
));
...
@@ -16,7 +20,11 @@ void test_repo_new__is_bare_until_workdir_set(void)
...
@@ -16,7 +20,11 @@ void test_repo_new__is_bare_until_workdir_set(void)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass
(
git_repository_new
(
&
repo
,
GIT_OID_SHA1
));
#else
cl_git_pass
(
git_repository_new
(
&
repo
));
cl_git_pass
(
git_repository_new
(
&
repo
));
#endif
cl_assert_equal_b
(
true
,
git_repository_is_bare
(
repo
));
cl_assert_equal_b
(
true
,
git_repository_is_bare
(
repo
));
cl_git_pass
(
git_repository_set_workdir
(
repo
,
clar_sandbox_path
(),
0
));
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)
...
@@ -25,3 +33,30 @@ void test_repo_new__is_bare_until_workdir_set(void)
git_repository_free
(
repo
);
git_repository_free
(
repo
);
}
}
void
test_repo_new__sha1
(
void
)
{
git_repository
*
repo
;
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass
(
git_repository_new
(
&
repo
,
GIT_OID_SHA1
));
#else
cl_git_pass
(
git_repository_new
(
&
repo
));
#endif
cl_assert_equal_i
(
GIT_OID_SHA1
,
git_repository_oid_type
(
repo
));
git_repository_free
(
repo
);
}
void
test_repo_new__sha256
(
void
)
{
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip
();
#else
git_repository
*
repo
;
cl_git_pass
(
git_repository_new
(
&
repo
,
GIT_OID_SHA256
));
cl_assert_equal_i
(
GIT_OID_SHA256
,
git_repository_oid_type
(
repo
));
git_repository_free
(
repo
);
#endif
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment