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
b0d37669
Commit
b0d37669
authored
Aug 03, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new iteration behavior to git_tree_walk
Missed this one, ironically enough.
parent
5dca2010
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
4 deletions
+109
-4
src/tree.c
+6
-4
tests-clar/object/tree/walk.c
+103
-0
No files found.
src/tree.c
View file @
b0d37669
...
...
@@ -787,9 +787,10 @@ static int tree_walk(
for
(
i
=
0
;
i
<
tree
->
entries
.
length
;
++
i
)
{
git_tree_entry
*
entry
=
tree
->
entries
.
contents
[
i
];
if
(
preorder
&&
(
error
=
callback
(
path
->
ptr
,
entry
,
payload
))
!=
0
)
if
(
preorder
&&
callback
(
path
->
ptr
,
entry
,
payload
))
{
error
=
GIT_EUSER
;
break
;
}
if
(
git_tree_entry__is_tree
(
entry
))
{
git_tree
*
subtree
;
...
...
@@ -814,10 +815,11 @@ static int tree_walk(
git_tree_free
(
subtree
);
}
if
(
!
preorder
&&
(
error
=
callback
(
path
->
ptr
,
entry
,
payload
))
!=
0
)
if
(
!
preorder
&&
callback
(
path
->
ptr
,
entry
,
payload
))
{
error
=
GIT_EUSER
;
break
;
}
}
return
error
;
}
...
...
tests-clar/object/tree/walk.c
0 → 100644
View file @
b0d37669
#include "clar_libgit2.h"
#include "tree.h"
static
const
char
*
tree_oid
=
"1810dff58d8a660512d4832e740f692884338ccd"
;
static
git_repository
*
g_repo
;
void
test_object_tree_walk__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
}
void
test_object_tree_walk__cleanup
(
void
)
{
cl_git_sandbox_cleanup
();
}
static
int
treewalk_count_cb
(
const
char
*
root
,
const
git_tree_entry
*
entry
,
void
*
payload
)
{
int
*
count
=
payload
;
GIT_UNUSED
(
root
);
GIT_UNUSED
(
entry
);
(
*
count
)
+=
1
;
return
0
;
}
void
test_object_tree_walk__0
(
void
)
{
git_oid
id
;
git_tree
*
tree
;
int
ct
;
git_oid_fromstr
(
&
id
,
tree_oid
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id
));
ct
=
0
;
cl_git_pass
(
git_tree_walk
(
tree
,
treewalk_count_cb
,
GIT_TREEWALK_PRE
,
&
ct
));
cl_assert_equal_i
(
3
,
ct
);
ct
=
0
;
cl_git_pass
(
git_tree_walk
(
tree
,
treewalk_count_cb
,
GIT_TREEWALK_POST
,
&
ct
));
cl_assert_equal_i
(
3
,
ct
);
git_tree_free
(
tree
);
}
static
int
treewalk_stop_cb
(
const
char
*
root
,
const
git_tree_entry
*
entry
,
void
*
payload
)
{
int
*
count
=
payload
;
GIT_UNUSED
(
root
);
GIT_UNUSED
(
entry
);
(
*
count
)
+=
1
;
return
(
*
count
==
2
);
}
static
int
treewalk_stop_immediately_cb
(
const
char
*
root
,
const
git_tree_entry
*
entry
,
void
*
payload
)
{
GIT_UNUSED
(
root
);
GIT_UNUSED
(
entry
);
GIT_UNUSED
(
payload
);
return
-
100
;
}
void
test_object_tree_walk__1
(
void
)
{
git_oid
id
;
git_tree
*
tree
;
int
ct
;
git_oid_fromstr
(
&
id
,
tree_oid
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
id
));
ct
=
0
;
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_cb
,
GIT_TREEWALK_PRE
,
&
ct
));
cl_assert_equal_i
(
2
,
ct
);
ct
=
0
;
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_cb
,
GIT_TREEWALK_POST
,
&
ct
));
cl_assert_equal_i
(
2
,
ct
);
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_immediately_cb
,
GIT_TREEWALK_PRE
,
NULL
));
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_immediately_cb
,
GIT_TREEWALK_POST
,
NULL
));
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