summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/diff_parse.c4
-rw-r--r--tests/diff/parse.c21
2 files changed, 24 insertions, 1 deletions
diff --git a/src/diff_parse.c b/src/diff_parse.c
index e640063af..93915683e 100644
--- a/src/diff_parse.c
+++ b/src/diff_parse.c
@@ -37,7 +37,6 @@ static git_diff_parsed *diff_parsed_alloc(void)
GIT_REFCOUNT_INC(diff);
diff->base.type = GIT_DIFF_TYPE_PARSED;
- diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
diff->base.strcomp = git__strcmp;
diff->base.strncomp = git__strncmp;
diff->base.pfxcomp = git__prefixcmp;
@@ -45,6 +44,9 @@ static git_diff_parsed *diff_parsed_alloc(void)
diff->base.patch_fn = git_patch_parsed_from_diff;
diff->base.free_fn = diff_parsed_free;
+ git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION);
+ diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
+
git_pool_init(&diff->base.pool, 1);
if (git_vector_init(&diff->patches, 0, NULL) < 0 ||
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 35870594a..acb6eb8a5 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -246,3 +246,24 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void)
git_diff_free(diff);
git_buf_free(&buf);
}
+
+void test_diff_parse__patch_roundtrip_succeeds(void)
+{
+ const char buf1[] = "a\n", buf2[] = "b\n";
+ git_buf patchbuf = GIT_BUF_INIT, diffbuf = GIT_BUF_INIT;
+ git_patch *patch;
+ git_diff *diff;
+
+ cl_git_pass(git_patch_from_buffers(&patch, buf1, strlen(buf1), "obj1", buf2, strlen(buf2), "obj2", NULL));
+ cl_git_pass(git_patch_to_buf(&patchbuf, patch));
+
+ cl_git_pass(git_diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size));
+ cl_git_pass(git_diff_to_buf(&diffbuf, diff, GIT_DIFF_FORMAT_PATCH));
+
+ cl_assert_equal_s(patchbuf.ptr, diffbuf.ptr);
+
+ git_patch_free(patch);
+ git_diff_free(diff);
+ git_buf_free(&patchbuf);
+ git_buf_free(&diffbuf);
+}