Commit ba02079f by Ben Straub

Avoid temporary object in lookup routine

parent 364d800b
...@@ -374,27 +374,26 @@ int git_object_lookup_bypath( ...@@ -374,27 +374,26 @@ int git_object_lookup_bypath(
int error = -1; int error = -1;
git_tree *tree = NULL; git_tree *tree = NULL;
git_tree_entry *entry = NULL; git_tree_entry *entry = NULL;
git_object *tmpobj = NULL;
assert(out && treeish && path); assert(out && treeish && path);
if (((error = git_object_peel((git_object**)&tree, treeish, GIT_OBJ_TREE)) < 0) || if ((error = git_object_peel((git_object**)&tree, treeish, GIT_OBJ_TREE) < 0) ||
((error = git_tree_entry_bypath(&entry, tree, path)) < 0) || (error = git_tree_entry_bypath(&entry, tree, path)) < 0)
((error = git_tree_entry_to_object(&tmpobj, git_object_owner(treeish), entry)) < 0))
{ {
goto cleanup; goto cleanup;
} }
if (type == GIT_OBJ_ANY || git_object_type(tmpobj) == type) { if (type != GIT_OBJ_ANY && git_tree_entry_type(entry) != type)
*out = tmpobj; {
} else {
giterr_set(GITERR_OBJECT, giterr_set(GITERR_OBJECT,
"object at path '%s' is not of the asked-for type %d", "object at path '%s' is not of the asked-for type %d",
path, type); path, type);
error = GIT_EINVALIDSPEC; error = GIT_EINVALIDSPEC;
git_object_free(tmpobj); goto cleanup;
} }
error = git_tree_entry_to_object(out, git_object_owner(treeish), entry);
cleanup: cleanup:
git_tree_entry_free(entry); git_tree_entry_free(entry);
git_tree_free(tree); git_tree_free(tree);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment