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
8351abc7
Commit
8351abc7
authored
Jun 23, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3249 from libgit2/cmn/repo-version-check
Check the repository version
parents
0c34fa50
16c73d38
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
10 deletions
+49
-10
src/repository.c
+32
-10
tests/repo/open.c
+17
-0
No files found.
src/repository.c
View file @
8351abc7
...
...
@@ -32,6 +32,8 @@
# include "win32/w32_util.h"
#endif
static
int
check_repositoryformatversion
(
git_config
*
config
);
#define GIT_FILE_CONTENT_PREFIX "gitdir:"
#define GIT_BRANCH_MASTER "master"
...
...
@@ -489,6 +491,7 @@ int git_repository_open_ext(
git_buf
path
=
GIT_BUF_INIT
,
parent
=
GIT_BUF_INIT
,
link_path
=
GIT_BUF_INIT
;
git_repository
*
repo
;
git_config
*
config
=
NULL
;
if
(
repo_ptr
)
*
repo_ptr
=
NULL
;
...
...
@@ -510,22 +513,36 @@ int git_repository_open_ext(
GITERR_CHECK_ALLOC
(
repo
->
path_gitlink
);
}
/*
* We'd like to have the config, but git doesn't particularly
* care if it's not there, so we need to deal with that.
*/
error
=
git_repository_config_snapshot
(
&
config
,
repo
);
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
if
(
config
&&
(
error
=
check_repositoryformatversion
(
config
))
<
0
)
goto
cleanup
;
if
((
flags
&
GIT_REPOSITORY_OPEN_BARE
)
!=
0
)
repo
->
is_bare
=
1
;
else
{
git_config
*
config
=
NULL
;
if
((
error
=
git_repository_config_snapshot
(
&
config
,
repo
))
<
0
||
(
error
=
load_config_data
(
repo
,
config
))
<
0
||
(
error
=
load_workdir
(
repo
,
config
,
&
parent
))
<
0
)
git_repository_free
(
repo
);
if
(
config
&&
((
error
=
load_config_data
(
repo
,
config
))
<
0
||
(
error
=
load_workdir
(
repo
,
config
,
&
parent
)))
<
0
)
goto
cleanup
;
}
cleanup:
git_buf_free
(
&
parent
);
git_config_free
(
config
);
}
if
(
!
error
)
if
(
error
<
0
)
git_repository_free
(
repo
);
else
*
repo_ptr
=
repo
;
git_buf_free
(
&
parent
);
return
error
;
}
...
...
@@ -931,9 +948,14 @@ bool git_repository__reserved_names(
static
int
check_repositoryformatversion
(
git_config
*
config
)
{
int
version
;
int
version
,
error
;
if
(
git_config_get_int32
(
&
version
,
config
,
"core.repositoryformatversion"
)
<
0
)
error
=
git_config_get_int32
(
&
version
,
config
,
"core.repositoryformatversion"
);
/* git ignores this if the config variable isn't there */
if
(
error
==
GIT_ENOTFOUND
)
return
0
;
if
(
error
<
0
)
return
-
1
;
if
(
GIT_REPO_VERSION
<
version
)
{
...
...
tests/repo/open.c
View file @
8351abc7
...
...
@@ -20,6 +20,23 @@ void test_repo_open__bare_empty_repo(void)
cl_assert
(
git_repository_workdir
(
repo
)
==
NULL
);
}
void
test_repo_open__format_version_1
(
void
)
{
git_buf
path
=
GIT_BUF_INIT
;
git_repository
*
repo
;
git_config
*
config
;
repo
=
cl_git_sandbox_init
(
"empty_bare.git"
);
cl_git_pass
(
git_repository_open
(
&
repo
,
"empty_bare.git"
));
cl_git_pass
(
git_repository_config__weakptr
(
&
config
,
repo
));
cl_git_pass
(
git_config_set_int32
(
config
,
"core.repositoryformatversion"
,
1
));
git_repository_free
(
repo
);
cl_git_fail
(
git_repository_open
(
&
repo
,
"empty_bare.git"
));
}
void
test_repo_open__standard_empty_repo_through_gitdir
(
void
)
{
git_repository
*
repo
;
...
...
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