summaryrefslogtreecommitdiff
path: root/src/object.c
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-09-16 16:20:38 -0700
committerBen Straub <bs@github.com>2013-09-16 16:23:50 -0700
commitceab4e260637dc8374d0348ee9a078ab1c16e4ad (patch)
tree25124d6ea0528f5f3355046f56aaac43ba78ec4d /src/object.c
parent549931679a77b280eb1f36afeda8930eb31d70f7 (diff)
downloadlibgit2-ceab4e260637dc8374d0348ee9a078ab1c16e4ad.tar.gz
Port blame from git.git
Diffstat (limited to 'src/object.c')
-rw-r--r--src/object.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/object.c b/src/object.c
index 9b8ccdd3e..53666ffe4 100644
--- a/src/object.c
+++ b/src/object.c
@@ -364,3 +364,39 @@ int git_object_dup(git_object **dest, git_object *source)
*dest = source;
return 0;
}
+
+int git_object_lookup_bypath(
+ git_object **out,
+ const git_object *treeish,
+ const char *path,
+ git_otype type)
+{
+ 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))
+ {
+ goto cleanup;
+ }
+
+ if (type == GIT_OBJ_ANY || git_object_type(tmpobj) == type) {
+ *out = tmpobj;
+ } else {
+ 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);
+ }
+
+cleanup:
+ git_tree_entry_free(entry);
+ git_tree_free(tree);
+ return error;
+}