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
e78aeefa
Commit
e78aeefa
authored
Sep 13, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3420 from ethomson/iterator
iterator: advance the tree iterator smartly
parents
9562ebcd
a1859e21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
42 deletions
+56
-42
src/iterator.c
+56
-42
No files found.
src/iterator.c
View file @
e78aeefa
...
...
@@ -640,8 +640,53 @@ static int tree_iterator__current_internal(
return
0
;
}
static
int
tree_iterator__advance
(
const
git_index_entry
**
out
,
git_iterator
*
self
);
static
int
tree_iterator__advance_into_internal
(
git_iterator
*
self
)
{
int
error
=
0
;
tree_iterator
*
ti
=
(
tree_iterator
*
)
self
;
if
(
tree_iterator__at_tree
(
ti
))
error
=
tree_iterator__push_frame
(
ti
);
return
error
;
}
static
int
tree_iterator__advance_internal
(
git_iterator
*
self
)
{
int
error
;
tree_iterator
*
ti
=
(
tree_iterator
*
)
self
;
tree_iterator_frame
*
tf
=
ti
->
head
;
if
(
tf
->
current
>=
tf
->
n_entries
)
return
GIT_ITEROVER
;
if
(
!
iterator__has_been_accessed
(
ti
))
return
0
;
if
(
iterator__do_autoexpand
(
ti
)
&&
iterator__include_trees
(
ti
)
&&
tree_iterator__at_tree
(
ti
))
return
tree_iterator__advance_into_internal
(
self
);
if
(
ti
->
path_has_filename
)
{
git_buf_rtruncate_at_char
(
&
ti
->
path
,
'/'
);
ti
->
path_has_filename
=
ti
->
entry_is_current
=
false
;
}
/* scan forward and up, advancing in frame or popping frame when done */
while
(
!
tree_iterator__move_to_next
(
ti
,
tf
)
&&
tree_iterator__pop_frame
(
ti
,
false
))
tf
=
ti
->
head
;
/* find next and load trees */
if
((
error
=
tree_iterator__set_next
(
ti
,
tf
))
<
0
)
return
error
;
/* deal with include_trees / auto_expand as needed */
if
(
!
iterator__include_trees
(
ti
)
&&
tree_iterator__at_tree
(
ti
))
return
tree_iterator__advance_into_internal
(
self
);
return
0
;
}
static
int
tree_iterator__current
(
const
git_index_entry
**
out
,
git_iterator
*
self
)
...
...
@@ -659,7 +704,7 @@ static int tree_iterator__current(
self
,
entry
->
path
,
strlen
(
entry
->
path
));
if
(
m
!=
ITERATOR_PATHLIST_MATCH
)
{
if
((
error
=
tree_iterator__advance
(
&
entry
,
self
))
<
0
)
if
((
error
=
tree_iterator__advance
_internal
(
self
))
<
0
)
return
error
;
entry
=
NULL
;
...
...
@@ -673,60 +718,29 @@ static int tree_iterator__current(
return
error
;
}
static
int
tree_iterator__advance
_into
(
static
int
tree_iterator__advance
(
const
git_index_entry
**
entry
,
git_iterator
*
self
)
{
int
error
=
0
;
tree_iterator
*
ti
=
(
tree_iterator
*
)
self
;
int
error
=
tree_iterator__advance_internal
(
self
);
iterator__clear_entry
(
entry
);
if
(
tree_iterator__at_tree
(
ti
))
error
=
tree_iterator__push_frame
(
ti
);
if
(
!
error
&&
entry
)
error
=
tree_iterator__current
(
entry
,
self
);
if
(
error
<
0
)
return
error
;
return
error
;
return
tree_iterator__current
(
entry
,
self
)
;
}
static
int
tree_iterator__advance
(
static
int
tree_iterator__advance
_into
(
const
git_index_entry
**
entry
,
git_iterator
*
self
)
{
int
error
;
tree_iterator
*
ti
=
(
tree_iterator
*
)
self
;
tree_iterator_frame
*
tf
=
ti
->
head
;
int
error
=
tree_iterator__advance_into_internal
(
self
);
iterator__clear_entry
(
entry
);
if
(
tf
->
current
>=
tf
->
n_entries
)
return
GIT_ITEROVER
;
if
(
!
iterator__has_been_accessed
(
ti
))
return
tree_iterator__current
(
entry
,
self
);
if
(
iterator__do_autoexpand
(
ti
)
&&
iterator__include_trees
(
ti
)
&&
tree_iterator__at_tree
(
ti
))
return
tree_iterator__advance_into
(
entry
,
self
);
if
(
ti
->
path_has_filename
)
{
git_buf_rtruncate_at_char
(
&
ti
->
path
,
'/'
);
ti
->
path_has_filename
=
ti
->
entry_is_current
=
false
;
}
/* scan forward and up, advancing in frame or popping frame when done */
while
(
!
tree_iterator__move_to_next
(
ti
,
tf
)
&&
tree_iterator__pop_frame
(
ti
,
false
))
tf
=
ti
->
head
;
/* find next and load trees */
if
((
error
=
tree_iterator__set_next
(
ti
,
tf
))
<
0
)
if
(
error
<
0
)
return
error
;
/* deal with include_trees / auto_expand as needed */
if
(
!
iterator__include_trees
(
ti
)
&&
tree_iterator__at_tree
(
ti
))
return
tree_iterator__advance_into
(
entry
,
self
);
return
tree_iterator__current
(
entry
,
self
);
}
...
...
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