Add methods to access internal attributes in git_repo Added several methods to access: - The ODB behind a repo - The SHA1 id behind a generic repo object - The type of a generic repo object Signed-off-by: Vicent Marti <tanoku@gmail.com>
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
diff --git a/src/git/repository.h b/src/git/repository.h
index 001e4e9..a61e5b6 100644
--- a/src/git/repository.h
+++ b/src/git/repository.h
@@ -49,6 +49,29 @@ GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb);
*/
GIT_EXTERN(git_repository_object *) git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type);
+/**
+ * Get the object database behind a Git repository
+ *
+ * @param repo a repository object
+ * @return a pointer to the object db
+ */
+GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo);
+
+/**
+ * Get the id (SHA1) of a repository object
+ *
+ * @param obj the repository object
+ * @return the SHA1 id
+ */
+const git_oid *git_repository_object_id(git_repository_object *obj);
+
+/**
+ * Get the object type of an object
+ *
+ * @param obj the repository object
+ * @return the object's type
+ */
+git_otype git_repository_object_type(git_repository_object *obj);
/**
* Free a reference to one of the objects in the repostory.
diff --git a/src/repository.c b/src/repository.c
index 86f2216..3f07bd6 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -138,6 +138,24 @@ void git_repository_object_free(git_repository_object *object)
}
}
+git_odb *git_repository_database(git_repository *repo)
+{
+ assert(repo);
+ return repo->db;
+}
+
+const git_oid *git_repository_object_id(git_repository_object *obj)
+{
+ assert(obj);
+ return &obj->id;
+}
+
+git_otype git_repository_object_type(git_repository_object *obj)
+{
+ assert(obj);
+ return obj->dbo.type;
+}
+
git_repository_object *git_repository_lookup(git_repository *repo, const git_oid *id, git_otype type)
{
static const size_t object_sizes[] = {