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
9432af36
Commit
9432af36
authored
Nov 17, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename `git_tree_frompath` to `git_tree_get_subtree`
That makes more sense to me.
parent
010879d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
22 deletions
+50
-22
include/git2/tree.h
+7
-7
src/tree.c
+42
-14
tests-clay/object/tree/frompath.c
+1
-1
No files found.
include/git2/tree.h
View file @
9432af36
...
@@ -269,19 +269,19 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons
...
@@ -269,19 +269,19 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons
GIT_EXTERN
(
int
)
git_treebuilder_write
(
git_oid
*
oid
,
git_repository
*
repo
,
git_treebuilder
*
bld
);
GIT_EXTERN
(
int
)
git_treebuilder_write
(
git_oid
*
oid
,
git_repository
*
repo
,
git_treebuilder
*
bld
);
/**
/**
* Retrieve
the tree object containing a tree entry, given
* Retrieve
a subtree contained in a tree, given its
*
a relative path to this tree entry
*
relative path.
*
*
* The returned tree is owned by the repository and
* The returned tree is owned by the repository and
* should be closed with the `git_object_close` method.
* should be closed with the `git_object_close` method.
*
*
* @param
parent_out Pointer where to store the parent
tree
* @param
subtree Pointer where to store the sub
tree
* @param root A previously loaded tree which will be the root of the relative path
* @param root A previously loaded tree which will be the root of the relative path
* @param
treeentry_path Path to the tree entry from which to extract the last tree object
* @param
subtree_path Path to the contained subtree
* @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to a
n
* @return GIT_SUCCESS on success; GIT_ENOTFOUND if the path does not lead to a
*
entry
, GIT_EINVALIDPATH or an error code
*
subtree
, GIT_EINVALIDPATH or an error code
*/
*/
GIT_EXTERN
(
int
)
git_tree_
frompath
(
git_tree
**
parent_out
,
git_tree
*
root
,
const
char
*
treeentry
_path
);
GIT_EXTERN
(
int
)
git_tree_
get_subtree
(
git_tree
**
subtree
,
git_tree
*
root
,
const
char
*
subtree
_path
);
/** Callback for the tree traversal method */
/** Callback for the tree traversal method */
typedef
int
(
*
git_treewalk_cb
)(
const
char
*
root
,
git_tree_entry
*
entry
);
typedef
int
(
*
git_treewalk_cb
)(
const
char
*
root
,
git_tree_entry
*
entry
);
...
...
src/tree.c
View file @
9432af36
...
@@ -610,7 +610,11 @@ void git_treebuilder_free(git_treebuilder *bld)
...
@@ -610,7 +610,11 @@ void git_treebuilder_free(git_treebuilder *bld)
git__free
(
bld
);
git__free
(
bld
);
}
}
static
int
tree_frompath
(
git_tree
**
parent_out
,
git_tree
*
root
,
const
char
*
treeentry_path
,
int
offset
)
static
int
tree_frompath
(
git_tree
**
parent_out
,
git_tree
*
root
,
const
char
*
treeentry_path
,
int
offset
)
{
{
char
*
slash_pos
=
NULL
;
char
*
slash_pos
=
NULL
;
const
git_tree_entry
*
entry
;
const
git_tree_entry
*
entry
;
...
@@ -618,15 +622,21 @@ static int tree_frompath(git_tree **parent_out, git_tree *root, const char *tree
...
@@ -618,15 +622,21 @@ static int tree_frompath(git_tree **parent_out, git_tree *root, const char *tree
git_tree
*
subtree
;
git_tree
*
subtree
;
if
(
!*
(
treeentry_path
+
offset
))
if
(
!*
(
treeentry_path
+
offset
))
return
git__rethrow
(
GIT_EINVALIDPATH
,
"Invalid relative path to a tree entry '%s'."
,
treeentry_path
);
return
git__rethrow
(
GIT_EINVALIDPATH
,
"Invalid relative path to a tree entry '%s'."
,
treeentry_path
);
slash_pos
=
(
char
*
)
strchr
(
treeentry_path
+
offset
,
'/'
);
slash_pos
=
(
char
*
)
strchr
(
treeentry_path
+
offset
,
'/'
);
if
(
slash_pos
==
NULL
)
if
(
slash_pos
==
NULL
)
return
git_tree_lookup
(
parent_out
,
root
->
object
.
repo
,
git_object_id
((
const
git_object
*
)
root
));
return
git_tree_lookup
(
parent_out
,
root
->
object
.
repo
,
git_object_id
((
const
git_object
*
)
root
)
);
if
(
slash_pos
==
treeentry_path
+
offset
)
if
(
slash_pos
==
treeentry_path
+
offset
)
return
git__rethrow
(
GIT_EINVALIDPATH
,
"Invalid relative path to a tree entry '%s'."
,
treeentry_path
);
return
git__rethrow
(
GIT_EINVALIDPATH
,
"Invalid relative path to a tree entry '%s'."
,
treeentry_path
);
*
slash_pos
=
'\0'
;
*
slash_pos
=
'\0'
;
...
@@ -636,28 +646,44 @@ static int tree_frompath(git_tree **parent_out, git_tree *root, const char *tree
...
@@ -636,28 +646,44 @@ static int tree_frompath(git_tree **parent_out, git_tree *root, const char *tree
*
slash_pos
=
'/'
;
*
slash_pos
=
'/'
;
if
(
entry
==
NULL
)
if
(
entry
==
NULL
)
return
git__rethrow
(
GIT_ENOTFOUND
,
"No tree entry can be found from the given tree and relative path '%s'."
,
treeentry_path
);
return
git__rethrow
(
GIT_ENOTFOUND
,
"No tree entry can be found from "
"the given tree and relative path '%s'."
,
treeentry_path
);
if
((
error
=
git_tree_lookup
(
&
subtree
,
root
->
object
.
repo
,
&
entry
->
oid
))
<
GIT_SUCCESS
)
error
=
git_tree_lookup
(
&
subtree
,
root
->
object
.
repo
,
&
entry
->
oid
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
return
error
;
error
=
tree_frompath
(
parent_out
,
subtree
,
treeentry_path
,
slash_pos
-
treeentry_path
+
1
);
error
=
tree_frompath
(
parent_out
,
subtree
,
treeentry_path
,
slash_pos
-
treeentry_path
+
1
);
git_tree_close
(
subtree
);
git_tree_close
(
subtree
);
return
error
;
return
error
;
}
}
int
git_tree_frompath
(
git_tree
**
parent_out
,
git_tree
*
root
,
const
char
*
treeentry_path
)
int
git_tree_get_subtree
(
git_tree
**
subtree
,
git_tree
*
root
,
const
char
*
subtree_path
)
{
{
char
buffer
[
GIT_PATH_MAX
];
char
buffer
[
GIT_PATH_MAX
];
assert
(
root
&&
treeentry
_path
);
assert
(
subtree
&&
root
&&
subtree
_path
);
str
cpy
(
buffer
,
treeentry_path
);
str
ncpy
(
buffer
,
subtree_path
,
GIT_PATH_MAX
);
return
tree_frompath
(
parent_out
,
root
,
buffer
,
0
);
return
tree_frompath
(
subtree
,
root
,
buffer
,
0
);
}
}
static
int
tree_walk_post
(
git_tree
*
tree
,
git_treewalk_cb
callback
,
char
*
root
,
size_t
root_len
)
static
int
tree_walk_post
(
git_tree
*
tree
,
git_treewalk_cb
callback
,
char
*
root
,
size_t
root_len
)
{
{
int
error
;
int
error
;
unsigned
int
i
;
unsigned
int
i
;
...
@@ -673,13 +699,15 @@ static int tree_walk_post(git_tree *tree, git_treewalk_cb callback, char *root,
...
@@ -673,13 +699,15 @@ static int tree_walk_post(git_tree *tree, git_treewalk_cb callback, char *root,
if
(
ENTRY_IS_TREE
(
entry
))
{
if
(
ENTRY_IS_TREE
(
entry
))
{
git_tree
*
subtree
;
git_tree
*
subtree
;
if
((
error
=
git_tree_lookup
(
&
subtree
,
tree
->
object
.
repo
,
&
entry
->
oid
))
<
0
)
if
((
error
=
git_tree_lookup
(
&
subtree
,
tree
->
object
.
repo
,
&
entry
->
oid
))
<
0
)
return
error
;
return
error
;
strcpy
(
root
+
root_len
,
entry
->
filename
);
strcpy
(
root
+
root_len
,
entry
->
filename
);
root
[
root_len
+
entry
->
filename_len
]
=
'/'
;
root
[
root_len
+
entry
->
filename_len
]
=
'/'
;
tree_walk_post
(
subtree
,
callback
,
root
,
root_len
+
entry
->
filename_len
+
1
);
tree_walk_post
(
subtree
,
callback
,
root
,
root_len
+
entry
->
filename_len
+
1
);
git_tree_close
(
subtree
);
git_tree_close
(
subtree
);
}
}
...
...
tests-clay/object/tree/frompath.c
View file @
9432af36
...
@@ -29,7 +29,7 @@ static void assert_tree_from_path(git_tree *root, const char *path, git_error ex
...
@@ -29,7 +29,7 @@ static void assert_tree_from_path(git_tree *root, const char *path, git_error ex
{
{
git_tree
*
containing_tree
=
NULL
;
git_tree
*
containing_tree
=
NULL
;
cl_assert
(
git_tree_
frompath
(
&
containing_tree
,
root
,
path
)
==
expected_result
);
cl_assert
(
git_tree_
get_subtree
(
&
containing_tree
,
root
,
path
)
==
expected_result
);
if
(
containing_tree
==
NULL
&&
expected_result
!=
GIT_SUCCESS
)
if
(
containing_tree
==
NULL
&&
expected_result
!=
GIT_SUCCESS
)
return
;
return
;
...
...
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