Add getter methods for object owners You can know access the owning repository of any existing object, or the repository on which a revision walker is working on. 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/src/git/repository.h b/src/git/repository.h
index 9658989..0a50fe1 100644
--- a/src/git/repository.h
+++ b/src/git/repository.h
@@ -96,7 +96,7 @@ GIT_EXTERN(git_object *) git_object_new(git_repository *repo, git_otype type);
* @param object Git object to write back
* @return 0 on success; otherwise an error code
*/
-int git_object_write(git_object *object);
+GIT_EXTERN(int) git_object_write(git_object *object);
/**
* Get the id (SHA1) of a repository object
@@ -107,7 +107,7 @@ int git_object_write(git_object *object);
* @param obj the repository object
* @return the SHA1 id
*/
-const git_oid *git_object_id(git_object *obj);
+GIT_EXTERN(const git_oid *) git_object_id(git_object *obj);
/**
* Get the object type of an object
@@ -115,7 +115,15 @@ const git_oid *git_object_id(git_object *obj);
* @param obj the repository object
* @return the object's type
*/
-git_otype git_object_type(git_object *obj);
+GIT_EXTERN(git_otype) git_object_type(git_object *obj);
+
+/**
+ * Get the repository that owns this object
+ *
+ * @param obj the object
+ * @return the repository who owns this object
+ */
+GIT_EXTERN(git_repository *) git_object_owner(git_object *obj);
/**
* Free a reference to one of the objects in the repository.
diff --git a/src/git/revwalk.h b/src/git/revwalk.h
index 87f199e..42ffbc3 100644
--- a/src/git/revwalk.h
+++ b/src/git/revwalk.h
@@ -97,6 +97,15 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
*/
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
+/**
+ * Return the repository on which this walker
+ * is operating.
+ *
+ * @param walk the revision walker
+ * @return the repository being walked
+ */
+GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/src/repository.c b/src/repository.c
index 202fa04..fe7b870 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -333,6 +333,12 @@ git_otype git_object_type(git_object *obj)
return obj->source.raw.type;
}
+git_repository *git_object_owner(git_object *obj)
+{
+ assert(obj);
+ return obj->repo;
+}
+
git_object *git_object_new(git_repository *repo, git_otype type)
{
git_object *object = NULL;
diff --git a/src/revwalk.c b/src/revwalk.c
index e8d686f..8cd444f 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -80,6 +80,12 @@ void git_revwalk_free(git_revwalk *walk)
free(walk);
}
+git_repository *git_revwalk_repository(git_revwalk *walk)
+{
+ assert(walk);
+ return walk->repo;
+}
+
void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
{
if (walk->walking)