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
3d22394a
Unverified
Commit
3d22394a
authored
Jun 27, 2019
by
Patrick Steinhardt
Committed by
GitHub
Jun 27, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4967 from tiennou/fix/4671
Incomplete commondir support
parents
c5448501
501c51b2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
70 deletions
+76
-70
include/git2/repository.h
+2
-1
include/git2/sys/repository.h
+5
-1
src/attr.c
+33
-40
src/ignore.c
+7
-10
src/odb.c
+1
-0
src/odb.h
+2
-1
src/repository.c
+26
-17
No files found.
include/git2/repository.h
View file @
3d22394a
...
...
@@ -438,7 +438,8 @@ typedef enum {
GIT_REPOSITORY_ITEM_HOOKS
,
GIT_REPOSITORY_ITEM_LOGS
,
GIT_REPOSITORY_ITEM_MODULES
,
GIT_REPOSITORY_ITEM_WORKTREES
GIT_REPOSITORY_ITEM_WORKTREES
,
GIT_REPOSITORY_ITEM__LAST
}
git_repository_item_t
;
/**
...
...
include/git2/sys/repository.h
View file @
3d22394a
...
...
@@ -25,6 +25,10 @@ GIT_BEGIN_DECL
* Note that this is only useful if you wish to associate the repository
* with a non-filesystem-backed object database and config store.
*
* Caveats: since this repository has no physical location, some systems
* can fail to function properly: locations under $GIT_DIR, $GIT_COMMON_DIR,
* or $GIT_INFO_DIR are impacted.
*
* @param out The blank repository
* @return 0 on success, or an error code
*/
...
...
@@ -39,7 +43,7 @@ GIT_EXTERN(int) git_repository_new(git_repository **out);
* There's no need to call this function directly unless you're
* trying to aggressively cleanup the repo before its
* deallocation. `git_repository_free` already performs this operation
* before deallocati
on
the repo.
* before deallocati
ng
the repo.
*/
GIT_EXTERN
(
void
)
git_repository__cleanup
(
git_repository
*
repo
);
...
...
src/attr.c
View file @
3d22394a
...
...
@@ -306,10 +306,10 @@ static int system_attr_file(
static
int
attr_setup
(
git_repository
*
repo
,
git_attr_session
*
attr_session
)
{
int
error
=
0
;
const
char
*
workdir
=
git_repository_workdir
(
repo
);
git_index
*
idx
=
NULL
;
git_buf
path
=
GIT_BUF_INIT
;
git_index
*
idx
=
NULL
;
const
char
*
workdir
;
int
error
=
0
;
if
(
attr_session
&&
attr_session
->
init_setup
)
return
0
;
...
...
@@ -317,42 +317,38 @@ static int attr_setup(git_repository *repo, git_attr_session *attr_session)
if
((
error
=
git_attr_cache__init
(
repo
))
<
0
)
return
error
;
/* preload attribute files that could contain macros so the
* definitions will be available for later file parsing
/*
* Preload attribute files that could contain macros so the
* definitions will be available for later file parsing.
*/
error
=
system_attr_file
(
&
path
,
attr_session
);
if
(
error
==
0
)
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
NULL
,
path
.
ptr
);
if
(
error
!=
GIT_ENOTFOUND
)
goto
out
;
if
((
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
NULL
,
git_repository_attr_cache
(
repo
)
->
cfg_attr_file
))
<
0
)
goto
out
;
if
((
error
=
system_attr_file
(
&
path
,
attr_session
))
<
0
||
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
NULL
,
path
.
ptr
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
)
goto
out
;
}
if
((
error
=
git_repository_item_path
(
&
path
,
repo
,
GIT_REPOSITORY_ITEM_INFO
))
<
0
)
if
((
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
NULL
,
git_repository_attr_cache
(
repo
)
->
cfg_attr_file
))
<
0
)
goto
out
;
if
((
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
path
.
ptr
,
GIT_ATTR_FILE_INREPO
))
<
0
)
goto
out
;
if
((
error
=
git_repository_item_path
(
&
path
,
repo
,
GIT_REPOSITORY_ITEM_INFO
))
<
0
||
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
path
.
ptr
,
GIT_ATTR_FILE_INREPO
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
)
goto
out
;
}
if
(
workdir
!=
NULL
&&
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
workdir
,
GIT_ATTR_FILE
))
<
0
)
goto
out
;
if
(
(
workdir
=
git_repository_workdir
(
repo
))
!=
NULL
&&
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_FILE
,
workdir
,
GIT_ATTR_FILE
))
<
0
)
goto
out
;
if
((
error
=
git_repository_index__weakptr
(
&
idx
,
repo
))
<
0
||
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_INDEX
,
NULL
,
GIT_ATTR_FILE
))
<
0
)
goto
out
;
(
error
=
preload_attr_file
(
repo
,
attr_session
,
GIT_ATTR_FILE__FROM_INDEX
,
NULL
,
GIT_ATTR_FILE
))
<
0
)
goto
out
;
if
(
attr_session
)
attr_session
->
init_setup
=
1
;
...
...
@@ -516,15 +512,12 @@ static int collect_attr_files(
* - $GIT_PREFIX/etc/gitattributes
*/
error
=
git_repository_item_path
(
&
attrfile
,
repo
,
GIT_REPOSITORY_ITEM_INFO
);
if
(
error
<
0
)
goto
cleanup
;
error
=
push_attr_file
(
repo
,
attr_session
,
files
,
GIT_ATTR_FILE__FROM_FILE
,
attrfile
.
ptr
,
GIT_ATTR_FILE_INREPO
);
if
(
error
<
0
)
goto
cleanup
;
if
((
error
=
git_repository_item_path
(
&
attrfile
,
repo
,
GIT_REPOSITORY_ITEM_INFO
))
<
0
||
(
error
=
push_attr_file
(
repo
,
attr_session
,
files
,
GIT_ATTR_FILE__FROM_FILE
,
attrfile
.
ptr
,
GIT_ATTR_FILE_INREPO
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
}
info
.
repo
=
repo
;
info
.
attr_session
=
attr_session
;
...
...
src/ignore.c
View file @
3d22394a
...
...
@@ -335,16 +335,13 @@ int git_ignore__for_path(
goto
cleanup
;
}
if
((
error
=
git_repository_item_path
(
&
infopath
,
repo
,
GIT_REPOSITORY_ITEM_INFO
))
<
0
)
goto
cleanup
;
/* load .git/info/exclude */
error
=
push_ignore_file
(
ignores
,
&
ignores
->
ign_global
,
infopath
.
ptr
,
GIT_IGNORE_FILE_INREPO
);
if
(
error
<
0
)
goto
cleanup
;
/* load .git/info/exclude if possible */
if
((
error
=
git_repository_item_path
(
&
infopath
,
repo
,
GIT_REPOSITORY_ITEM_INFO
))
<
0
||
(
error
=
push_ignore_file
(
ignores
,
&
ignores
->
ign_global
,
infopath
.
ptr
,
GIT_IGNORE_FILE_INREPO
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
error
=
0
;
}
/* load core.excludesfile */
if
(
git_repository_attr_cache
(
repo
)
->
cfg_excl_file
!=
NULL
)
...
...
src/odb.c
View file @
3d22394a
...
...
@@ -548,6 +548,7 @@ int git_odb__add_default_backends(
#else
if
(
p_stat
(
objects_dir
,
&
st
)
<
0
)
{
if
(
as_alternates
)
/* this should warn */
return
0
;
git_error_set
(
GIT_ERROR_ODB
,
"failed to load object database in '%s'"
,
objects_dir
);
...
...
src/odb.h
View file @
3d22394a
...
...
@@ -71,6 +71,7 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj);
* Format the object header such as it would appear in the on-disk object
*/
int
git_odb__format_object_header
(
size_t
*
out_len
,
char
*
hdr
,
size_t
hdr_size
,
git_off_t
obj_len
,
git_object_t
obj_type
);
/*
* Hash an open file descriptor.
* This is a performance call when the contents of a fd need to be hashed,
...
...
@@ -95,7 +96,7 @@ int git_odb__hashfd_filtered(
* symlink, then the raw contents of the symlink will be hashed. Otherwise,
* this will fallback to `git_odb__hashfd`.
*
* The hash type for this call is always `GIT_OBJ
I
ECT_BLOB` because
* The hash type for this call is always `GIT_OBJECT_BLOB` because
* symlinks may only point to blobs.
*/
int
git_odb__hashlink
(
git_oid
*
out
,
const
char
*
path
);
...
...
src/repository.c
View file @
3d22394a
...
...
@@ -42,23 +42,24 @@ bool git_repository__fsync_gitdir = false;
static
const
struct
{
git_repository_item_t
parent
;
git_repository_item_t
fallback
;
const
char
*
name
;
bool
directory
;
}
items
[]
=
{
{
GIT_REPOSITORY_ITEM_GITDIR
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_WORKDIR
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_GITDIR
,
"index"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"objects"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"refs"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"packed-refs"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"remotes"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"config"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"info"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"hooks"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"logs"
,
true
},
{
GIT_REPOSITORY_ITEM_GITDIR
,
"modules"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
"worktrees"
,
true
}
{
GIT_REPOSITORY_ITEM_GITDIR
,
GIT_REPOSITORY_ITEM__LAST
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_WORKDIR
,
GIT_REPOSITORY_ITEM__LAST
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM__LAST
,
NULL
,
true
},
{
GIT_REPOSITORY_ITEM_GITDIR
,
GIT_REPOSITORY_ITEM__LAST
,
"index"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"objects"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"refs"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"packed-refs"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"remotes"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"config"
,
false
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"info"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"hooks"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"logs"
,
true
},
{
GIT_REPOSITORY_ITEM_GITDIR
,
GIT_REPOSITORY_ITEM__LAST
,
"modules"
,
true
},
{
GIT_REPOSITORY_ITEM_COMMONDIR
,
GIT_REPOSITORY_ITEM_GITDIR
,
"worktrees"
,
true
}
};
static
int
check_repositoryformatversion
(
git_config
*
config
);
...
...
@@ -2308,11 +2309,11 @@ int git_repository_is_empty(git_repository *repo)
return
is_empty
;
}
int
git_repository_item_path
(
git_buf
*
out
,
const
git_repository
*
repo
,
git_repository_item_t
item
)
static
const
char
*
resolved_parent_path
(
const
git_repository
*
repo
,
git_repository_item_t
item
,
git_repository_item_t
fallback
)
{
const
char
*
parent
;
switch
(
item
s
[
item
].
parent
)
{
switch
(
item
)
{
case
GIT_REPOSITORY_ITEM_GITDIR
:
parent
=
git_repository_path
(
repo
);
break
;
...
...
@@ -2324,9 +2325,17 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
break
;
default:
git_error_set
(
GIT_ERROR_INVALID
,
"invalid item directory"
);
return
-
1
;
return
NULL
;
}
if
(
!
parent
&&
fallback
!=
GIT_REPOSITORY_ITEM__LAST
)
return
resolved_parent_path
(
repo
,
fallback
,
GIT_REPOSITORY_ITEM__LAST
);
return
parent
;
}
int
git_repository_item_path
(
git_buf
*
out
,
const
git_repository
*
repo
,
git_repository_item_t
item
)
{
const
char
*
parent
=
resolved_parent_path
(
repo
,
items
[
item
].
parent
,
items
[
item
].
fallback
);
if
(
parent
==
NULL
)
{
git_error_set
(
GIT_ERROR_INVALID
,
"path cannot exist in repository"
);
return
GIT_ENOTFOUND
;
...
...
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