diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-03-14 10:37:47 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-03-14 13:08:28 +0100 |
commit | ace3508f4c2ad7f821bc79d0b34e7ac55fac4d12 (patch) | |
tree | 505985d35ce72604a26691b48770b44447358456 /tests/diff/parse.c | |
parent | 41019152a03815be27139764ceed05fd5a0e4b58 (diff) | |
download | libgit2-ace3508f4c2ad7f821bc79d0b34e7ac55fac4d12.tar.gz |
patch_generate: fix `git_diff_foreach` only working with generated diffs
The current logic of `git_diff_foreach` makes the assumption that all
diffs passed in are actually derived from generated diffs. With these
assumptions we try to derive the actual diff by inspecting either the
working directory files or blobs of a repository. This obviously cannot
work for diffs parsed from a file, where we do not necessarily have a
repository at hand.
Since the introduced split of parsed and generated patches, there are
multiple functions which help us to handle patches generically, being
indifferent from where they stem from. Use these functions and remove
the old logic specific to generated patches. This allows re-using the
same code for invoking the callbacks on the deltas.
Diffstat (limited to 'tests/diff/parse.c')
-rw-r--r-- | tests/diff/parse.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/diff/parse.c b/tests/diff/parse.c index a06813d1b..b79b19e8e 100644 --- a/tests/diff/parse.c +++ b/tests/diff/parse.c @@ -196,3 +196,32 @@ void test_diff_parse__get_patch_from_diff(void) cl_git_sandbox_cleanup(); } + +static int file_cb(const git_diff_delta *delta, float progress, void *payload) +{ + int *called = (int *) payload; + GIT_UNUSED(delta); + GIT_UNUSED(progress); + (*called)++; + return 0; +} + +void test_diff_parse__foreach_works_with_parsed_patch(void) +{ + const char patch[] = + "diff --git a/obj1 b/obj2\n" + "index 1234567..7654321 10644\n" + "--- a/obj1\n" + "+++ b/obj2\n" + "@@ -1 +1 @@\n" + "-abcde\n" + "+12345\n"; + int called = 0; + git_diff *diff; + + cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch))); + cl_git_pass(git_diff_foreach(diff, file_cb, NULL, NULL, NULL, &called)); + cl_assert_equal_i(called, 1); + + git_diff_free(diff); +} |