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
e120123e
Commit
e120123e
authored
Nov 20, 2012
by
Russell Belfer
Committed by
Ben Straub
Nov 27, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API review / update for tree.h
parent
824cb2d5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
29 deletions
+37
-29
examples/general.c
+2
-2
include/git2/tree.h
+0
-0
src/index.c
+1
-1
src/iterator.c
+1
-1
src/notes.c
+5
-5
src/pack-objects.c
+1
-1
src/tree.c
+21
-13
tests-clar/object/tree/walk.c
+6
-6
No files found.
examples/general.c
View file @
e120123e
...
...
@@ -261,8 +261,8 @@ int main (int argc, char** argv)
git_tree_lookup
(
&
tree
,
repo
,
&
oid
);
// Getting the count of entries in the tree so you can iterate over them if you want to.
in
t
cnt
=
git_tree_entrycount
(
tree
);
// 3
printf
(
"tree entries: %d
\n
"
,
cnt
);
size_
t
cnt
=
git_tree_entrycount
(
tree
);
// 3
printf
(
"tree entries: %d
\n
"
,
(
int
)
cnt
);
entry
=
git_tree_entry_byindex
(
tree
,
0
);
printf
(
"Entry name: %s
\n
"
,
git_tree_entry_name
(
entry
));
// "hello.c"
...
...
include/git2/tree.h
View file @
e120123e
This diff is collapsed.
Click to expand it.
src/index.c
View file @
e120123e
...
...
@@ -1603,7 +1603,7 @@ int git_index_read_tree(git_index *index, git_tree *tree)
{
git_index_clear
(
index
);
return
git_tree_walk
(
tree
,
read_tree_cb
,
GIT_TREEWALK_POST
,
index
);
return
git_tree_walk
(
tree
,
GIT_TREEWALK_POST
,
read_tree_cb
,
index
);
}
git_repository
*
git_index_owner
(
const
git_index
*
index
)
...
...
src/iterator.c
View file @
e120123e
...
...
@@ -85,7 +85,7 @@ struct tree_iterator_frame {
tree_iterator_frame
*
next
,
*
prev
;
git_tree
*
tree
;
char
*
start
;
unsigned
in
t
index
;
size_
t
index
;
};
typedef
struct
{
...
...
src/notes.c
View file @
e120123e
...
...
@@ -19,11 +19,11 @@ static int find_subtree_in_current_level(
const
char
*
annotated_object_sha
,
int
fanout
)
{
unsigned
in
t
i
;
size_
t
i
;
const
git_tree_entry
*
entry
;
*
out
=
NULL
;
if
(
parent
==
NULL
)
return
GIT_ENOTFOUND
;
...
...
@@ -34,12 +34,12 @@ static int find_subtree_in_current_level(
continue
;
if
(
S_ISDIR
(
git_tree_entry_filemode
(
entry
))
&&
strlen
(
git_tree_entry_name
(
entry
))
==
2
&&
strlen
(
git_tree_entry_name
(
entry
))
==
2
&&
!
strncmp
(
git_tree_entry_name
(
entry
),
annotated_object_sha
+
fanout
,
2
))
return
git_tree_lookup
(
out
,
repo
,
git_tree_entry_id
(
entry
));
/* Not a DIR, so do we have an already existing blob? */
if
(
!
strcmp
(
git_tree_entry_name
(
entry
),
annotated_object_sha
+
fanout
))
if
(
!
strcmp
(
git_tree_entry_name
(
entry
),
annotated_object_sha
+
fanout
))
return
GIT_EEXISTS
;
}
...
...
@@ -71,7 +71,7 @@ static int find_subtree_r(git_tree **out, git_tree *root,
static
int
find_blob
(
git_oid
*
blob
,
git_tree
*
tree
,
const
char
*
target
)
{
unsigned
in
t
i
;
size_
t
i
;
const
git_tree_entry
*
entry
;
for
(
i
=
0
;
i
<
git_tree_entrycount
(
tree
);
i
++
)
{
...
...
src/pack-objects.c
View file @
e120123e
...
...
@@ -1284,7 +1284,7 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
git_packbuilder_insert
(
pb
,
oid
,
NULL
)
<
0
)
return
-
1
;
if
(
git_tree_walk
(
tree
,
cb_tree_walk
,
GIT_TREEWALK_PRE
,
pb
)
<
0
)
{
if
(
git_tree_walk
(
tree
,
GIT_TREEWALK_PRE
,
cb_tree_walk
,
pb
)
<
0
)
{
git_tree_free
(
tree
);
return
-
1
;
}
...
...
src/tree.c
View file @
e120123e
...
...
@@ -166,6 +166,7 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
return
NULL
;
memcpy
(
copy
,
entry
,
total_size
);
return
copy
;
}
...
...
@@ -288,10 +289,10 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
return
at_pos
;
}
unsigned
in
t
git_tree_entrycount
(
const
git_tree
*
tree
)
size_
t
git_tree_entrycount
(
const
git_tree
*
tree
)
{
assert
(
tree
);
return
(
unsigned
int
)
tree
->
entries
.
length
;
return
tree
->
entries
.
length
;
}
static
int
tree_error
(
const
char
*
str
)
...
...
@@ -694,7 +695,10 @@ on_error:
return
-
1
;
}
void
git_treebuilder_filter
(
git_treebuilder
*
bld
,
int
(
*
filter
)(
const
git_tree_entry
*
,
void
*
),
void
*
payload
)
void
git_treebuilder_filter
(
git_treebuilder
*
bld
,
git_treebuilder_filter_cb
filter
,
void
*
payload
)
{
unsigned
int
i
;
...
...
@@ -855,23 +859,27 @@ static int tree_walk(
return
error
;
}
int
git_tree_walk
(
git_tree
*
tree
,
git_treewalk_cb
callback
,
int
mode
,
void
*
payload
)
int
git_tree_walk
(
git_tree
*
tree
,
git_treewalk_mode
mode
,
git_treewalk_cb
callback
,
void
*
payload
)
{
int
error
=
0
;
git_buf
root_path
=
GIT_BUF_INIT
;
switch
(
mode
)
{
case
GIT_TREEWALK_POST
:
error
=
tree_walk
(
tree
,
callback
,
&
root_path
,
payload
,
false
);
break
;
case
GIT_TREEWALK_POST
:
error
=
tree_walk
(
tree
,
callback
,
&
root_path
,
payload
,
false
);
break
;
case
GIT_TREEWALK_PRE
:
error
=
tree_walk
(
tree
,
callback
,
&
root_path
,
payload
,
true
);
break
;
case
GIT_TREEWALK_PRE
:
error
=
tree_walk
(
tree
,
callback
,
&
root_path
,
payload
,
true
);
break
;
default
:
giterr_set
(
GITERR_INVALID
,
"Invalid walking mode for tree walk"
);
return
-
1
;
default
:
giterr_set
(
GITERR_INVALID
,
"Invalid walking mode for tree walk"
);
return
-
1
;
}
git_buf_free
(
&
root_path
);
...
...
tests-clar/object/tree/walk.c
View file @
e120123e
...
...
@@ -38,11 +38,11 @@ void test_object_tree_walk__0(void)
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_git_pass
(
git_tree_walk
(
tree
,
GIT_TREEWALK_PRE
,
treewalk_count_cb
,
&
ct
));
cl_assert_equal_i
(
3
,
ct
);
ct
=
0
;
cl_git_pass
(
git_tree_walk
(
tree
,
treewalk_count_cb
,
GIT_TREEWALK_POST
,
&
ct
));
cl_git_pass
(
git_tree_walk
(
tree
,
GIT_TREEWALK_POST
,
treewalk_count_cb
,
&
ct
));
cl_assert_equal_i
(
3
,
ct
);
git_tree_free
(
tree
);
...
...
@@ -83,21 +83,21 @@ void test_object_tree_walk__1(void)
ct
=
0
;
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_cb
,
GIT_TREEWALK_PRE
,
&
ct
));
GIT_EUSER
,
git_tree_walk
(
tree
,
GIT_TREEWALK_PRE
,
treewalk_stop_cb
,
&
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
));
GIT_EUSER
,
git_tree_walk
(
tree
,
GIT_TREEWALK_POST
,
treewalk_stop_cb
,
&
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
));
tree
,
GIT_TREEWALK_PRE
,
treewalk_stop_immediately_cb
,
NULL
));
cl_assert_equal_i
(
GIT_EUSER
,
git_tree_walk
(
tree
,
treewalk_stop_immediately_cb
,
GIT_TREEWALK_POST
,
NULL
));
tree
,
GIT_TREEWALK_POST
,
treewalk_stop_immediately_cb
,
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