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
c1b024fb
Commit
c1b024fb
authored
Feb 17, 2023
by
Miguel Arroz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6491: Sets oid_type on repos open with git_repository_open_bare
parent
795758d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
22 deletions
+51
-22
src/libgit2/repository.c
+48
-22
tests/libgit2/repo/open.c
+3
-0
No files found.
src/libgit2/repository.c
View file @
c1b024fb
...
@@ -733,6 +733,43 @@ out:
...
@@ -733,6 +733,43 @@ out:
return
error
;
return
error
;
}
}
static
int
obtain_config_and_set_oid_type
(
git_config
**
config_ptr
,
git_repository
*
repo
)
{
int
error
;
git_config
*
config
=
NULL
;
int
version
=
0
;
/*
* 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
out
;
if
(
config
&&
(
error
=
check_repositoryformatversion
(
&
version
,
config
))
<
0
)
goto
out
;
if
((
error
=
check_extensions
(
config
,
version
))
<
0
)
goto
out
;
if
(
version
>
0
)
{
if
((
error
=
load_objectformat
(
repo
,
config
))
<
0
)
goto
out
;
}
else
{
repo
->
oid_type
=
GIT_OID_SHA1
;
}
out:
*
config_ptr
=
config
;
return
error
;
}
int
git_repository_open_bare
(
int
git_repository_open_bare
(
git_repository
**
repo_ptr
,
git_repository
**
repo_ptr
,
const
char
*
bare_path
)
const
char
*
bare_path
)
...
@@ -741,6 +778,7 @@ int git_repository_open_bare(
...
@@ -741,6 +778,7 @@ int git_repository_open_bare(
git_repository
*
repo
=
NULL
;
git_repository
*
repo
=
NULL
;
bool
is_valid
;
bool
is_valid
;
int
error
;
int
error
;
git_config
*
config
;
if
((
error
=
git_fs_path_prettify_dir
(
&
path
,
bare_path
,
NULL
))
<
0
||
if
((
error
=
git_fs_path_prettify_dir
(
&
path
,
bare_path
,
NULL
))
<
0
||
(
error
=
is_valid_repository_path
(
&
is_valid
,
&
path
,
&
common_path
))
<
0
)
(
error
=
is_valid_repository_path
(
&
is_valid
,
&
path
,
&
common_path
))
<
0
)
...
@@ -766,8 +804,15 @@ int git_repository_open_bare(
...
@@ -766,8 +804,15 @@ int git_repository_open_bare(
repo
->
is_worktree
=
0
;
repo
->
is_worktree
=
0
;
repo
->
workdir
=
NULL
;
repo
->
workdir
=
NULL
;
if
((
error
=
obtain_config_and_set_oid_type
(
&
config
,
repo
))
<
0
)
goto
cleanup
;
*
repo_ptr
=
repo
;
*
repo_ptr
=
repo
;
return
0
;
cleanup:
git_config_free
(
config
);
return
error
;
}
}
static
int
_git_repository_open_ext_from_env
(
static
int
_git_repository_open_ext_from_env
(
...
@@ -1007,20 +1052,8 @@ int git_repository_open_ext(
...
@@ -1007,20 +1052,8 @@ int git_repository_open_ext(
goto
cleanup
;
goto
cleanup
;
repo
->
is_worktree
=
is_worktree
;
repo
->
is_worktree
=
is_worktree
;
/*
error
=
obtain_config_and_set_oid_type
(
&
config
,
repo
);
* We'd like to have the config, but git doesn't particularly
if
(
error
<
0
)
* 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
(
&
version
,
config
))
<
0
)
goto
cleanup
;
if
((
error
=
check_extensions
(
config
,
version
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
flags
&
GIT_REPOSITORY_OPEN_BARE
)
!=
0
)
{
if
((
flags
&
GIT_REPOSITORY_OPEN_BARE
)
!=
0
)
{
...
@@ -1032,13 +1065,6 @@ int git_repository_open_ext(
...
@@ -1032,13 +1065,6 @@ int git_repository_open_ext(
goto
cleanup
;
goto
cleanup
;
}
}
if
(
version
>
0
)
{
if
((
error
=
load_objectformat
(
repo
,
config
))
<
0
)
goto
cleanup
;
}
else
{
repo
->
oid_type
=
GIT_OID_SHA1
;
}
/*
/*
* Ensure that the git directory and worktree are
* Ensure that the git directory and worktree are
* owned by the current user.
* owned by the current user.
...
...
tests/libgit2/repo/open.c
View file @
c1b024fb
...
@@ -410,6 +410,7 @@ void test_repo_open__no_config(void)
...
@@ -410,6 +410,7 @@ void test_repo_open__no_config(void)
git_str_dispose
(
&
path
);
git_str_dispose
(
&
path
);
cl_git_pass
(
git_repository_open
(
&
repo
,
"empty_standard_repo"
));
cl_git_pass
(
git_repository_open
(
&
repo
,
"empty_standard_repo"
));
cl_assert
(
git_repository_oid_type
(
repo
)
==
GIT_OID_SHA1
);
cl_git_pass
(
git_repository_config
(
&
config
,
repo
));
cl_git_pass
(
git_repository_config
(
&
config
,
repo
));
cl_git_pass
(
git_config_set_string
(
config
,
"test.set"
,
"42"
));
cl_git_pass
(
git_config_set_string
(
config
,
"test.set"
,
"42"
));
...
@@ -433,11 +434,13 @@ void test_repo_open__force_bare(void)
...
@@ -433,11 +434,13 @@ void test_repo_open__force_bare(void)
cl_git_pass
(
git_repository_open
(
&
barerepo
,
"alternate"
));
cl_git_pass
(
git_repository_open
(
&
barerepo
,
"alternate"
));
cl_assert
(
!
git_repository_is_bare
(
barerepo
));
cl_assert
(
!
git_repository_is_bare
(
barerepo
));
cl_assert
(
git_repository_oid_type
(
barerepo
)
==
GIT_OID_SHA1
);
git_repository_free
(
barerepo
);
git_repository_free
(
barerepo
);
cl_git_pass
(
git_repository_open_bare
(
cl_git_pass
(
git_repository_open_bare
(
&
barerepo
,
"empty_standard_repo/.git"
));
&
barerepo
,
"empty_standard_repo/.git"
));
cl_assert
(
git_repository_is_bare
(
barerepo
));
cl_assert
(
git_repository_is_bare
(
barerepo
));
cl_assert
(
git_repository_oid_type
(
barerepo
)
==
GIT_OID_SHA1
);
git_repository_free
(
barerepo
);
git_repository_free
(
barerepo
);
cl_git_fail
(
git_repository_open_bare
(
&
barerepo
,
"alternate/.git"
));
cl_git_fail
(
git_repository_open_bare
(
&
barerepo
,
"alternate/.git"
));
...
...
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