Commit 02eb1711283473c1f2e8dba6005467ef8e275855

Edward Thomson 2021-02-01T10:07:00

Merge pull request #5731 from KOLANICH-libs/owner_accessor patch: add owner accessor

diff --git a/include/git2/patch.h b/include/git2/patch.h
index b177798..fde9659 100644
--- a/include/git2/patch.h
+++ b/include/git2/patch.h
@@ -29,6 +29,14 @@ GIT_BEGIN_DECL
 typedef struct git_patch git_patch;
 
 /**
+ * Get the repository associated with this patch. May be NULL.
+ *
+ * @param patch the patch
+ * @return a pointer to the repository
+ */
+GIT_EXTERN(git_repository *) git_patch_owner(const git_patch *patch);
+
+/**
  * Return a patch for an entry in the diff list.
  *
  * The `git_patch` is a newly created object contains the text diffs
diff --git a/src/patch.c b/src/patch.c
index 8f8bd7a..f02c928 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -204,6 +204,11 @@ int git_patch_get_line_in_hunk(
 	return 0;
 }
 
+git_repository *git_patch_owner(const git_patch *patch)
+{
+	return patch->repo;
+}
+
 int git_patch_from_diff(git_patch **out, git_diff *diff, size_t idx)
 {
 	GIT_ASSERT_ARG(out);