Add getters for `git_odb_object`
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
diff --git a/include/git2/odb.h b/include/git2/odb.h
index 8926b44..1a0f0e6 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -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
diff --git a/src/odb.c b/src/odb.c
index 9aeaa8a..d825fd9 100644
--- 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);