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
dfd7fcc4
Unverified
Commit
dfd7fcc4
authored
Apr 02, 2020
by
Patrick Steinhardt
Committed by
GitHub
Apr 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5388 from bk2204/repo-format-v1
Handle repository format v1
parents
e1299171
06f02300
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
9 deletions
+84
-9
src/repository.c
+38
-9
tests/repo/open.c
+46
-0
No files found.
src/repository.c
View file @
dfd7fcc4
...
...
@@ -62,7 +62,8 @@ static const struct {
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"worktrees"
,
true
}
};
static
int
check_repositoryformatversion
(
git_config
*
config
);
static
int
check_repositoryformatversion
(
int
*
version
,
git_config
*
config
);
static
int
check_extensions
(
git_config
*
config
,
int
version
);
#define GIT_COMMONDIR_FILE "commondir"
#define GIT_GITDIR_FILE "gitdir"
...
...
@@ -72,6 +73,7 @@ static int check_repositoryformatversion(git_config *config);
#define GIT_BRANCH_MASTER "master"
#define GIT_REPO_VERSION 0
#define GIT_REPO_MAX_VERSION 1
git_buf
git_repository__reserved_names_win32
[]
=
{
{
DOT_GIT
,
0
,
CONST_STRLEN
(
DOT_GIT
)
},
...
...
@@ -813,6 +815,7 @@ int git_repository_open_ext(
gitlink
=
GIT_BUF_INIT
,
commondir
=
GIT_BUF_INIT
;
git_repository
*
repo
=
NULL
;
git_config
*
config
=
NULL
;
int
version
=
0
;
if
(
flags
&
GIT_REPOSITORY_OPEN_FROM_ENV
)
return
_git_repository_open_ext_from_env
(
repo_ptr
,
start_path
);
...
...
@@ -854,7 +857,10 @@ int git_repository_open_ext(
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
if
(
config
&&
(
error
=
check_repositoryformatversion
(
config
))
<
0
)
if
(
config
&&
(
error
=
check_repositoryformatversion
(
&
version
,
config
))
<
0
)
goto
cleanup
;
if
((
error
=
check_extensions
(
config
,
version
)
<
0
))
goto
cleanup
;
if
((
flags
&
GIT_REPOSITORY_OPEN_BARE
)
!=
0
)
...
...
@@ -1350,11 +1356,11 @@ bool git_repository__reserved_names(
}
#endif
static
int
check_repositoryformatversion
(
git_config
*
config
)
static
int
check_repositoryformatversion
(
int
*
version
,
git_config
*
config
)
{
int
version
,
error
;
int
error
;
error
=
git_config_get_int32
(
&
version
,
config
,
"core.repositoryformatversion"
);
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
;
...
...
@@ -1362,16 +1368,35 @@ static int check_repositoryformatversion(git_config *config)
if
(
error
<
0
)
return
-
1
;
if
(
GIT_REPO_
VERSION
<
version
)
{
if
(
GIT_REPO_
MAX_VERSION
<
*
version
)
{
git_error_set
(
GIT_ERROR_REPOSITORY
,
"unsupported repository version %d
. Only versions up to %d are supported.
"
,
version
,
GIT_REPO
_VERSION
);
"unsupported repository version %d
; only versions up to %d are supported
"
,
*
version
,
GIT_REPO_MAX
_VERSION
);
return
-
1
;
}
return
0
;
}
static
int
check_valid_extension
(
const
git_config_entry
*
entry
,
void
*
payload
)
{
GIT_UNUSED
(
payload
);
if
(
!
strcmp
(
entry
->
name
,
"extensions.noop"
))
return
0
;
git_error_set
(
GIT_ERROR_REPOSITORY
,
"unsupported extension name %s"
,
entry
->
name
);
return
-
1
;
}
static
int
check_extensions
(
git_config
*
config
,
int
version
)
{
if
(
version
<
1
)
return
0
;
return
git_config_foreach_match
(
config
,
"^extensions
\\
."
,
check_valid_extension
,
NULL
);
}
int
git_repository_create_head
(
const
char
*
git_dir
,
const
char
*
ref_name
)
{
git_buf
ref_path
=
GIT_BUF_INIT
;
...
...
@@ -1583,11 +1608,15 @@ static int repo_init_config(
git_config
*
config
=
NULL
;
bool
is_bare
=
((
flags
&
GIT_REPOSITORY_INIT_BARE
)
!=
0
);
bool
is_reinit
=
((
flags
&
GIT_REPOSITORY_INIT__IS_REINIT
)
!=
0
);
int
version
=
0
;
if
((
error
=
repo_local_config
(
&
config
,
&
cfg_path
,
NULL
,
repo_dir
))
<
0
)
goto
cleanup
;
if
(
is_reinit
&&
(
error
=
check_repositoryformatversion
(
config
))
<
0
)
if
(
is_reinit
&&
(
error
=
check_repositoryformatversion
(
&
version
,
config
))
<
0
)
goto
cleanup
;
if
((
error
=
check_extensions
(
config
,
version
)
<
0
))
goto
cleanup
;
#define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \
...
...
tests/repo/open.c
View file @
dfd7fcc4
...
...
@@ -35,7 +35,53 @@ void test_repo_open__format_version_1(void)
git_config_free
(
config
);
git_repository_free
(
repo
);
git_repository_open
(
&
repo
,
"empty_bare.git"
);
cl_assert
(
git_repository_path
(
repo
)
!=
NULL
);
cl_assert
(
git__suffixcmp
(
git_repository_path
(
repo
),
"/"
)
==
0
);
git_repository_free
(
repo
);
}
void
test_repo_open__format_version_1_with_valid_extension
(
void
)
{
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
(
&
config
,
repo
));
cl_git_pass
(
git_config_set_int32
(
config
,
"core.repositoryformatversion"
,
1
));
cl_git_pass
(
git_config_set_int32
(
config
,
"extensions.noop"
,
1
));
git_config_free
(
config
);
git_repository_free
(
repo
);
git_repository_open
(
&
repo
,
"empty_bare.git"
);
cl_assert
(
git_repository_path
(
repo
)
!=
NULL
);
cl_assert
(
git__suffixcmp
(
git_repository_path
(
repo
),
"/"
)
==
0
);
git_repository_free
(
repo
);
}
void
test_repo_open__format_version_1_with_invalid_extension
(
void
)
{
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
(
&
config
,
repo
));
cl_git_pass
(
git_config_set_int32
(
config
,
"core.repositoryformatversion"
,
1
));
cl_git_pass
(
git_config_set_int32
(
config
,
"extensions.invalid"
,
1
));
git_config_free
(
config
);
git_repository_free
(
repo
);
cl_git_fail
(
git_repository_open
(
&
repo
,
"empty_bare.git"
));
git_repository_free
(
repo
);
}
void
test_repo_open__standard_empty_repo_through_gitdir
(
void
)
...
...
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