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
8cf2de07
Commit
8cf2de07
authored
Oct 19, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree: Fix lookups by entry name
parent
5fa1bed0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
include/git2/tree.h
+6
-0
src/tree.c
+11
-2
No files found.
include/git2/tree.h
View file @
8cf2de07
...
@@ -88,6 +88,9 @@ GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree);
...
@@ -88,6 +88,9 @@ GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree);
/**
/**
* Lookup a tree entry by its filename
* Lookup a tree entry by its filename
*
*
* Note that if the entry in the tree is a folder instead of
* a standard file, the given name must be ended with a slash.
*
* @param tree a previously loaded tree.
* @param tree a previously loaded tree.
* @param filename the filename of the desired entry
* @param filename the filename of the desired entry
* @return the tree entry; NULL if not found
* @return the tree entry; NULL if not found
...
@@ -203,6 +206,9 @@ GIT_EXTERN(void) git_treebuilder_free(git_treebuilder *bld);
...
@@ -203,6 +206,9 @@ GIT_EXTERN(void) git_treebuilder_free(git_treebuilder *bld);
/**
/**
* Get an entry from the builder from its filename
* Get an entry from the builder from its filename
*
*
* Note that if the entry in the tree is a folder instead of
* a standard file, the given name must be ended with a slash.
*
* The returned entry is owned by the builder and should
* The returned entry is owned by the builder and should
* not be freed manually.
* not be freed manually.
*
*
...
...
src/tree.c
View file @
8cf2de07
...
@@ -23,6 +23,7 @@ static int valid_attributes(const int attributes)
...
@@ -23,6 +23,7 @@ static int valid_attributes(const int attributes)
struct
tree_key_search
{
struct
tree_key_search
{
const
char
*
filename
;
const
char
*
filename
;
size_t
filename_len
;
size_t
filename_len
;
int
is_folder
;
};
};
static
int
entry_search_cmp
(
const
void
*
key
,
const
void
*
array_member
)
static
int
entry_search_cmp
(
const
void
*
key
,
const
void
*
array_member
)
...
@@ -32,7 +33,7 @@ static int entry_search_cmp(const void *key, const void *array_member)
...
@@ -32,7 +33,7 @@ static int entry_search_cmp(const void *key, const void *array_member)
int
result
=
int
result
=
git_futils_cmp_path
(
git_futils_cmp_path
(
ksearch
->
filename
,
ksearch
->
filename_len
,
entry
->
attr
&
040000
,
ksearch
->
filename
,
ksearch
->
filename_len
,
ksearch
->
is_folder
,
entry
->
filename
,
entry
->
filename_len
,
entry
->
attr
&
040000
);
entry
->
filename
,
entry
->
filename_len
,
entry
->
attr
&
040000
);
return
result
?
result
:
((
int
)
ksearch
->
filename_len
-
(
int
)
entry
->
filename_len
);
return
result
?
result
:
((
int
)
ksearch
->
filename_len
-
(
int
)
entry
->
filename_len
);
...
@@ -51,15 +52,19 @@ static int entry_sort_cmp(const void *a, const void *b)
...
@@ -51,15 +52,19 @@ static int entry_sort_cmp(const void *a, const void *b)
static
int
build_ksearch
(
struct
tree_key_search
*
ksearch
,
const
char
*
path
)
static
int
build_ksearch
(
struct
tree_key_search
*
ksearch
,
const
char
*
path
)
{
{
size_t
len
=
strlen
(
path
);
size_t
len
=
strlen
(
path
);
int
is_folder
=
0
;
if
(
len
&&
path
[
len
-
1
]
==
'/'
)
if
(
len
&&
path
[
len
-
1
]
==
'/'
)
{
is_folder
=
1
;
len
--
;
len
--
;
}
if
(
len
==
0
||
memchr
(
path
,
'/'
,
len
)
!=
NULL
)
if
(
len
==
0
||
memchr
(
path
,
'/'
,
len
)
!=
NULL
)
return
GIT_ERROR
;
return
GIT_ERROR
;
ksearch
->
filename
=
path
;
ksearch
->
filename
=
path
;
ksearch
->
filename_len
=
len
;
ksearch
->
filename_len
=
len
;
ksearch
->
is_folder
=
is_folder
;
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
}
}
...
@@ -420,6 +425,10 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
...
@@ -420,6 +425,10 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
if
(
build_ksearch
(
&
ksearch
,
filename
)
<
GIT_SUCCESS
)
if
(
build_ksearch
(
&
ksearch
,
filename
)
<
GIT_SUCCESS
)
return
git__throw
(
GIT_ERROR
,
"Failed to insert entry. Invalid filename '%s'"
,
filename
);
return
git__throw
(
GIT_ERROR
,
"Failed to insert entry. Invalid filename '%s'"
,
filename
);
if
((
attributes
&
040000
)
!=
0
)
{
ksearch
.
is_folder
=
1
;
}
if
((
pos
=
git_vector_bsearch2
(
&
bld
->
entries
,
entry_search_cmp
,
&
ksearch
))
!=
GIT_ENOTFOUND
)
{
if
((
pos
=
git_vector_bsearch2
(
&
bld
->
entries
,
entry_search_cmp
,
&
ksearch
))
!=
GIT_ENOTFOUND
)
{
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
if
(
entry
->
removed
)
{
if
(
entry
->
removed
)
{
...
...
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