Avoid temporary object in lookup routine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/object.c b/src/object.c
index 53666ff..3fc984b 100644
--- a/src/object.c
+++ b/src/object.c
@@ -374,27 +374,26 @@ int git_object_lookup_bypath(
int error = -1;
git_tree *tree = NULL;
git_tree_entry *entry = NULL;
- git_object *tmpobj = NULL;
assert(out && treeish && path);
- 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_to_object(&tmpobj, git_object_owner(treeish), entry)) < 0))
+ if ((error = git_object_peel((git_object**)&tree, treeish, GIT_OBJ_TREE) < 0) ||
+ (error = git_tree_entry_bypath(&entry, tree, path)) < 0)
{
goto cleanup;
}
- if (type == GIT_OBJ_ANY || git_object_type(tmpobj) == type) {
- *out = tmpobj;
- } else {
+ if (type != GIT_OBJ_ANY && git_tree_entry_type(entry) != type)
+ {
giterr_set(GITERR_OBJECT,
"object at path '%s' is not of the asked-for type %d",
path, type);
error = GIT_EINVALIDSPEC;
- git_object_free(tmpobj);
+ goto cleanup;
}
+ error = git_tree_entry_to_object(out, git_object_owner(treeish), entry);
+
cleanup:
git_tree_entry_free(entry);
git_tree_free(tree);