mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-04 08:32:03 +00:00
Rename git_tree_frompath
to git_tree_get_subtree
That makes more sense to me.
This commit is contained in:
parent
010879d9e7
commit
9432af36fc
@ -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 subtree
|
||||||
* @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 an
|
* @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);
|
||||||
|
56
src/tree.c
56
src/tree.c
@ -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
|
|||||||
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
|
|||||||
*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);
|
||||||
|
|
||||||
strcpy(buffer, treeentry_path);
|
strncpy(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,
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user