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
c097f717
Commit
c097f717
authored
Aug 17, 2015
by
Leo Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New API: git_index_find_prefix
Find the first index entry matching a prefix.
parent
1cef6b9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
0 deletions
+56
-0
include/git2/index.h
+11
-0
src/index.c
+24
-0
tests/index/tests.c
+21
-0
No files found.
include/git2/index.h
View file @
c097f717
...
...
@@ -643,6 +643,17 @@ GIT_EXTERN(int) git_index_update_all(
*/
GIT_EXTERN
(
int
)
git_index_find
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
path
);
/**
* Find the first position of any entries matching a prefix. To find the first position
* of a path inside a given folder, suffix the prefix with a '/'.
*
* @param at_pos the address to which the position of the index entry is written (optional)
* @param index an existing index object
* @param prefix the prefix to search for
* @return 0 with valid value in at_pos; an error code otherwise
*/
GIT_EXTERN
(
int
)
git_index_find_prefix
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
prefix
);
/**@}*/
/** @name Conflict Index Entry Functions
...
...
src/index.c
View file @
c097f717
...
...
@@ -1420,6 +1420,30 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
return
error
;
}
int
git_index_find_prefix
(
size_t
*
at_pos
,
git_index
*
index
,
const
char
*
prefix
)
{
int
error
=
0
;
size_t
pos
;
const
git_index_entry
*
entry
;
if
(
git_mutex_lock
(
&
index
->
lock
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"Failed to lock index"
);
return
-
1
;
}
index_find
(
&
pos
,
index
,
prefix
,
strlen
(
prefix
),
GIT_INDEX_STAGE_ANY
,
false
);
entry
=
git_vector_get
(
&
index
->
entries
,
pos
);
if
(
!
entry
||
git__prefixcmp
(
entry
->
path
,
prefix
)
!=
0
)
error
=
GIT_ENOTFOUND
;
if
(
!
error
&&
at_pos
)
*
at_pos
=
pos
;
git_mutex_unlock
(
&
index
->
lock
);
return
error
;
}
int
git_index__find_pos
(
size_t
*
out
,
git_index
*
index
,
const
char
*
path
,
size_t
path_len
,
int
stage
)
{
...
...
tests/index/tests.c
View file @
c097f717
...
...
@@ -155,6 +155,27 @@ void test_index_tests__find_in_empty(void)
git_index_free
(
index
);
}
void
test_index_tests__find_prefix
(
void
)
{
git_index
*
index
;
const
git_index_entry
*
entry
;
size_t
pos
;
cl_git_pass
(
git_index_open
(
&
index
,
TEST_INDEX_PATH
));
cl_git_pass
(
git_index_find_prefix
(
&
pos
,
index
,
"src"
));
entry
=
git_index_get_byindex
(
index
,
pos
);
cl_assert
(
git__strcmp
(
entry
->
path
,
"src/block-sha1/sha1.c"
)
==
0
);
cl_git_pass
(
git_index_find_prefix
(
&
pos
,
index
,
"src/co"
));
entry
=
git_index_get_byindex
(
index
,
pos
);
cl_assert
(
git__strcmp
(
entry
->
path
,
"src/commit.c"
)
==
0
);
cl_assert
(
GIT_ENOTFOUND
==
git_index_find_prefix
(
NULL
,
index
,
"blah"
));
git_index_free
(
index
);
}
void
test_index_tests__write
(
void
)
{
git_index
*
index
;
...
...
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