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
1af84271
Commit
1af84271
authored
Aug 30, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree_iterator: use a pathlist
parent
4a0dbeb0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
1 deletions
+148
-1
src/iterator.c
+34
-1
tests/repo/iterator.c
+114
-0
No files found.
src/iterator.c
View file @
1af84271
...
...
@@ -560,7 +560,7 @@ static int tree_iterator__update_entry(tree_iterator *ti)
return
0
;
}
static
int
tree_iterator__current
(
static
int
tree_iterator__current
_internal
(
const
git_index_entry
**
entry
,
git_iterator
*
self
)
{
int
error
;
...
...
@@ -583,6 +583,39 @@ static int tree_iterator__current(
return
0
;
}
int
tree_iterator__advance
(
const
git_index_entry
**
out
,
git_iterator
*
self
);
static
int
tree_iterator__current
(
const
git_index_entry
**
out
,
git_iterator
*
self
)
{
git_index_entry
*
entry
=
NULL
;
iterator_pathlist__match_t
m
;
int
error
;
do
{
if
((
error
=
tree_iterator__current_internal
(
&
entry
,
self
))
<
0
)
return
error
;
if
(
self
->
pathlist
.
length
)
{
m
=
iterator_pathlist__match
(
self
,
entry
->
path
,
strlen
(
entry
->
path
));
if
(
m
!=
ITERATOR_PATHLIST_MATCH
)
{
if
((
error
=
tree_iterator__advance
(
&
entry
,
self
))
<
0
)
return
error
;
entry
=
NULL
;
}
}
}
while
(
!
entry
);
if
(
out
)
*
out
=
entry
;
return
error
;
}
static
int
tree_iterator__advance_into
(
const
git_index_entry
**
entry
,
git_iterator
*
self
)
{
...
...
tests/repo/iterator.c
View file @
1af84271
...
...
@@ -1332,3 +1332,117 @@ void test_repo_iterator__workdirfilelist_icase(void)
git_vector_free
(
&
filelist
);
}
void
test_repo_iterator__treefilelist
(
void
)
{
git_iterator
*
i
;
git_iterator_options
i_opts
=
GIT_ITERATOR_OPTIONS_INIT
;
git_vector
filelist
;
git_tree
*
tree
;
bool
default_icase
;
int
expect
;
cl_git_pass
(
git_vector_init
(
&
filelist
,
100
,
&
git__strcmp_cb
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"B"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"c"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"D"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"e"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k.a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k.b"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k/1"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k/a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"kZZZZZZZ"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"L/1"
));
g_repo
=
cl_git_sandbox_init
(
"icase"
);
git_repository_head_tree
(
&
tree
,
g_repo
);
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
/* In this test we DO NOT force a case on the iteratords and verify default behavior. */
i_opts
.
pathlist
.
strings
=
(
char
**
)
filelist
.
contents
;
i_opts
.
pathlist
.
count
=
filelist
.
length
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
expect_iterator_items
(
i
,
8
,
NULL
,
8
,
NULL
);
git_iterator_free
(
i
);
i_opts
.
start
=
"c"
;
i_opts
.
end
=
NULL
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
default_icase
=
git_iterator_ignore_case
(
i
);
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect
=
((
default_icase
)
?
6
:
4
);
expect_iterator_items
(
i
,
expect
,
NULL
,
expect
,
NULL
);
git_iterator_free
(
i
);
i_opts
.
start
=
NULL
;
i_opts
.
end
=
"e"
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
default_icase
=
git_iterator_ignore_case
(
i
);
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect
=
((
default_icase
)
?
5
:
6
);
expect_iterator_items
(
i
,
expect
,
NULL
,
expect
,
NULL
);
git_iterator_free
(
i
);
git_vector_free
(
&
filelist
);
git_tree_free
(
tree
);
}
void
test_repo_iterator__treefilelist_icase
(
void
)
{
git_iterator
*
i
;
git_iterator_options
i_opts
=
GIT_ITERATOR_OPTIONS_INIT
;
git_vector
filelist
;
git_tree
*
tree
;
cl_git_pass
(
git_vector_init
(
&
filelist
,
100
,
&
git__strcmp_cb
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"B"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"c"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"D"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"e"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k.a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k.b"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k/1"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"k/a"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"kZZZZ"
));
cl_git_pass
(
git_vector_insert
(
&
filelist
,
"L/1"
));
g_repo
=
cl_git_sandbox_init
(
"icase"
);
git_repository_head_tree
(
&
tree
,
g_repo
);
i_opts
.
flags
=
GIT_ITERATOR_DONT_IGNORE_CASE
;
i_opts
.
pathlist
.
strings
=
(
char
**
)
filelist
.
contents
;
i_opts
.
pathlist
.
count
=
filelist
.
length
;
i_opts
.
start
=
"c"
;
i_opts
.
end
=
"k/D"
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
expect_iterator_items
(
i
,
3
,
NULL
,
3
,
NULL
);
git_iterator_free
(
i
);
i_opts
.
start
=
"k"
;
i_opts
.
end
=
"k/Z"
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
expect_iterator_items
(
i
,
1
,
NULL
,
1
,
NULL
);
git_iterator_free
(
i
);
i_opts
.
flags
=
GIT_ITERATOR_IGNORE_CASE
;
i_opts
.
start
=
"c"
;
i_opts
.
end
=
"k/D"
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
expect_iterator_items
(
i
,
5
,
NULL
,
5
,
NULL
);
git_iterator_free
(
i
);
i_opts
.
start
=
"k"
;
i_opts
.
end
=
"k/Z"
;
cl_git_pass
(
git_iterator_for_tree
(
&
i
,
tree
,
&
i_opts
));
expect_iterator_items
(
i
,
2
,
NULL
,
2
,
NULL
);
git_iterator_free
(
i
);
git_vector_free
(
&
filelist
);
git_tree_free
(
tree
);
}
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