Tree: Added a function that returns the type of a tree entry.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 0caf60a..7b682b3 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -129,6 +129,14 @@ GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry);
GIT_EXTERN(const git_oid *) git_tree_entry_id(const git_tree_entry *entry);
/**
+ * Get the type of the object pointed by the entry
+ *
+ * @param entry a tree entry
+ * @return the type of the pointed object
+ */
+GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry);
+
+/**
* Convert a tree entry to the git_object it points too.
*
* @param object pointer to the converted object
diff --git a/src/fileops.h b/src/fileops.h
index 4a86e1c..c114508 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -20,6 +20,9 @@
#define GIT_PLATFORM_PATH_SEP '/'
#endif
+#define S_IFGITLINK 0160000
+#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
+
#ifdef GIT_WIN32
GIT_INLINE(int) link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new))
{
diff --git a/src/tree.c b/src/tree.c
index 60413e2..d539f83 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -100,6 +100,18 @@ const git_oid *git_tree_entry_id(const git_tree_entry *entry)
return &entry->oid;
}
+git_otype git_tree_entry_type(const git_tree_entry *entry)
+{
+ assert(entry);
+
+ if (S_ISGITLINK(entry->attr))
+ return GIT_OBJ_COMMIT;
+ else if (S_ISDIR(entry->attr))
+ return GIT_OBJ_TREE;
+ else
+ return GIT_OBJ_BLOB;
+}
+
int git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry)
{
assert(entry && object_out);