]> git.proxmox.com Git - libgit2.git/commitdiff
Tree: Added a function that returns the type of a tree entry.
authorRomain Geissler <romain.geissler@gmail.com>
Mon, 6 Jun 2011 15:14:30 +0000 (17:14 +0200)
committerRomain Geissler <romain.geissler@gmail.com>
Mon, 6 Jun 2011 15:14:30 +0000 (17:14 +0200)
include/git2/tree.h
src/fileops.h
src/tree.c

index 0caf60a48f2352cc428835448288f516c5c737e1..7b682b306fdad31995fe63286cb00ff0def38b9d 100644 (file)
@@ -128,6 +128,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.
  *
index 4a86e1c63c2c18247744992230e7a9a1cfe6fc90..c114508db3fdbfa7c75a2103c528abb59ff6a22e 100644 (file)
@@ -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))
 {
index 60413e276a36cca2bd78b24cbfbd31240a530fbc..d539f83e28881ccc770e50e5059cbd6e4aa7a75f 100644 (file)
@@ -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);