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
3589587d
Commit
3589587d
authored
Apr 24, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repo: factor the commondir detection
parent
e5851c62
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
22 deletions
+35
-22
src/repository.c
+35
-22
No files found.
src/repository.c
View file @
3589587d
...
@@ -186,49 +186,62 @@ void git_repository_free(git_repository *repo)
...
@@ -186,49 +186,62 @@ void git_repository_free(git_repository *repo)
git__free
(
repo
);
git__free
(
repo
);
}
}
/*
/* Check if we have a separate commondir (e.g. we have a worktree) */
* Git repository open methods
static
int
lookup_commondir
(
git_buf
*
out
,
git_buf
*
repository_path
)
*
* Open a repository object from its path
*/
static
int
is_valid_repository_path
(
bool
*
out
,
git_buf
*
repository_path
,
git_buf
*
common_path
)
{
{
git_buf
common_link
=
GIT_BUF_INIT
;
int
error
;
int
error
;
*
out
=
false
;
/*
* If there's no commondir file, the repository path is the
* common path, but it needs a trailing slash.
*/
if
(
!
git_path_contains_file
(
repository_path
,
GIT_COMMONDIR_FILE
))
{
if
((
error
=
git_buf_set
(
out
,
repository_path
->
ptr
,
repository_path
->
size
))
==
0
)
error
=
git_path_to_dir
(
out
);
/* Check if we have a separate commondir (e.g. we have a
goto
done
;
* worktree) */
}
if
(
git_path_contains_file
(
repository_path
,
GIT_COMMONDIR_FILE
))
{
git_buf
common_link
=
GIT_BUF_INIT
;
if
((
error
=
git_buf_joinpath
(
&
common_link
,
repository_path
->
ptr
,
GIT_COMMONDIR_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
common_link
,
repository_path
->
ptr
,
GIT_COMMONDIR_FILE
))
<
0
||
(
error
=
git_futils_readbuffer
(
&
common_link
,
common_link
.
ptr
))
<
0
)
(
error
=
git_futils_readbuffer
(
&
common_link
,
common_link
.
ptr
))
<
0
)
return
error
;
goto
done
;
git_buf_rtrim
(
&
common_link
);
git_buf_rtrim
(
&
common_link
);
if
(
git_path_is_relative
(
common_link
.
ptr
))
{
if
(
git_path_is_relative
(
common_link
.
ptr
))
{
if
((
error
=
git_buf_joinpath
(
common_path
,
repository_path
->
ptr
,
common_link
.
ptr
))
<
0
)
if
((
error
=
git_buf_joinpath
(
out
,
repository_path
->
ptr
,
common_link
.
ptr
))
<
0
)
return
error
;
goto
done
;
}
else
{
}
else
{
git_buf_swap
(
common_path
,
&
common_link
);
git_buf_swap
(
out
,
&
common_link
);
}
}
git_buf_dispose
(
&
common_link
);
git_buf_dispose
(
&
common_link
);
}
else
{
/* Make sure the commondir path always has a trailing slash */
if
((
error
=
git_buf_set
(
common_path
,
repository_path
->
ptr
,
repository_path
->
size
))
<
0
)
error
=
git_path_prettify_dir
(
out
,
out
->
ptr
,
NULL
);
done:
return
error
;
return
error
;
}
}
/*
* Git repository open methods
*
* Open a repository object from its path
*/
static
int
is_valid_repository_path
(
bool
*
out
,
git_buf
*
repository_path
,
git_buf
*
common_path
)
{
int
error
;
*
out
=
false
;
/* Make sure the commondir path always has a trailing * slash */
if
((
error
=
lookup_commondir
(
common_path
,
repository_path
))
<
0
)
if
(
git_buf_rfind
(
common_path
,
'/'
)
!=
(
ssize_t
)
common_path
->
size
-
1
)
if
((
error
=
git_buf_putc
(
common_path
,
'/'
))
<
0
)
return
error
;
return
error
;
/* Ensure HEAD file exists */
/* Ensure HEAD file exists */
if
(
git_path_contains_file
(
repository_path
,
GIT_HEAD_FILE
)
==
false
)
if
(
git_path_contains_file
(
repository_path
,
GIT_HEAD_FILE
)
==
false
)
return
0
;
return
0
;
/* Check files in common dir */
/* Check files in common dir */
if
(
git_path_contains_dir
(
common_path
,
GIT_OBJECTS_DIR
)
==
false
)
if
(
git_path_contains_dir
(
common_path
,
GIT_OBJECTS_DIR
)
==
false
)
return
0
;
return
0
;
...
...
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