summaryrefslogtreecommitdiff
path: root/src/patch_parse.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-08-23 23:38:39 -0500
committerEdward Thomson <ethomson@github.com>2016-08-24 09:08:57 -0500
commitb859faa61ce3f1fda5c29ac1e72a3d58fee2ede6 (patch)
tree976a27f8827db4200a172720b547fbf7ec1db119 /src/patch_parse.c
parentc60210d36780a39db669e52d6d592d339c6a2ed3 (diff)
downloadlibgit2-ethomson/patch_from_diff.tar.gz
Teach `git_patch_from_diff` about parsed diffsethomson/patch_from_diff
Ensure that `git_patch_from_diff` can return the patch for parsed diffs, not just generate a patch for a generated diff.
Diffstat (limited to 'src/patch_parse.c')
-rw-r--r--src/patch_parse.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 82d2d3e2e..44bcf8f75 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -7,6 +7,7 @@
#include "git2/patch.h"
#include "patch.h"
#include "patch_parse.h"
+#include "diff_parse.h"
#include "path.h"
#define parse_err(...) \
@@ -1025,6 +1026,20 @@ void git_patch_parse_ctx_free(git_patch_parse_ctx *ctx)
GIT_REFCOUNT_DEC(ctx, patch_parse_ctx_free);
}
+int git_patch_parsed_from_diff(git_patch **out, git_diff *d, size_t idx)
+{
+ git_diff_parsed *diff = (git_diff_parsed *)d;
+ git_patch *p;
+
+ if ((p = git_vector_get(&diff->patches, idx)) == NULL)
+ return -1;
+
+ GIT_REFCOUNT_INC(p);
+ *out = p;
+
+ return 0;
+}
+
static void patch_parsed__free(git_patch *p)
{
git_patch_parsed *patch = (git_patch_parsed *)p;