]> git.proxmox.com Git - libgit2.git/commitdiff
Add getters for `git_odb_object`
authorVicent Marti <tanoku@gmail.com>
Mon, 21 Mar 2011 18:28:02 +0000 (20:28 +0200)
committerVicent Marti <tanoku@gmail.com>
Tue, 22 Mar 2011 18:38:33 +0000 (20:38 +0200)
include/git2/odb.h
src/odb.c

index 8926b446cc6e1d7d295d81110d4b78a636e0a035..1a0f0e64c5b3a584356b3b15ae98aadca82d4c61 100644 (file)
@@ -235,6 +235,48 @@ GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otyp
  */
 GIT_EXTERN(void) git_odb_object_close(git_odb_object *object);
 
+/**
+ * Return the OID of an ODB object
+ *
+ * This is the OID from which the object was read from
+ *
+ * @param object the object
+ * @return a pointer to the OID
+ */
+GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object);
+
+/**
+ * Return the data of an ODB object
+ *
+ * This is the uncompressed, raw data as read from the ODB,
+ * without the leading header.
+ *
+ * This pointer is owned by the object and shall not be free'd.
+ *
+ * @param object the object
+ * @return a pointer to the data
+ */
+GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object);
+
+/**
+ * Return the size of an ODB object
+ *
+ * This is the real size of the `data` buffer, not the
+ * actual size of the object.
+ *
+ * @param object the object
+ * @return the size
+ */
+GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
+
+/**
+ * Return the type of an ODB object
+ *
+ * @param object the object
+ * @return the type
+ */
+GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
+
 /** @} */
 GIT_END_DECL
 #endif
index 9aeaa8a239e785b2f7b0c7fecbddddb54600a07c..d825fd95c98d9f0aa71bc1653eb753a0791af1d2 100644 (file)
--- a/src/odb.c
+++ b/src/odb.c
@@ -109,6 +109,26 @@ static void free_odb_object(void *o)
        }
 }
 
+const git_oid *git_odb_object_id(git_odb_object *object)
+{
+       return &object->cached.oid;
+}
+
+const void *git_odb_object_data(git_odb_object *object)
+{
+       return object->raw.data;
+}
+
+size_t git_odb_object_size(git_odb_object *object)
+{
+       return object->raw.len;
+}
+
+git_otype git_odb_object_type(git_odb_object *object)
+{
+       return object->raw.type;
+}
+
 void git_odb_object_close(git_odb_object *object)
 {
        git_cached_obj_decref((git_cached_obj *)object, &free_odb_object);