From f335ecd6e126aa9dea28786522c0e6ce71596e91 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 30 Aug 2012 14:24:16 -0700 Subject: Diff iterators This refactors the diff output code so that an iterator object can be used to traverse and generate the diffs, instead of just the `foreach()` style with callbacks. The code has been rearranged so that the two styles can still share most functions. This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses that as a common error code for marking the end of iteration when using a iterator style of object. --- tests-clar/diff/diffiter.c | 116 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tests-clar/diff/diffiter.c (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c new file mode 100644 index 000000000..56c254741 --- /dev/null +++ b/tests-clar/diff/diffiter.c @@ -0,0 +1,116 @@ +#include "clar_libgit2.h" +#include "diff_helpers.h" + +void test_diff_diffiter__initialize(void) +{ +} + +void test_diff_diffiter__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_diff_diffiter__create(void) +{ + git_repository *repo = cl_git_sandbox_init("attr"); + git_diff_list *diff; + git_diff_iterator *iter; + + cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_iterator_new(&iter, diff)); + git_diff_iterator_free(iter); + git_diff_list_free(diff); +} + +void test_diff_diffiter__iterate_files(void) +{ + git_repository *repo = cl_git_sandbox_init("attr"); + git_diff_list *diff; + git_diff_iterator *iter; + git_diff_delta *delta; + int error, count = 0; + + cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_iterator_new(&iter, diff)); + + while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(delta != NULL); + count++; + } + + cl_assert_equal_i(GIT_ITEROVER, error); + cl_assert(delta == NULL); + cl_assert_equal_i(6, count); + + git_diff_iterator_free(iter); + git_diff_list_free(diff); +} + +void test_diff_diffiter__iterate_files_2(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_list *diff; + git_diff_iterator *iter; + git_diff_delta *delta; + int error, count = 0; + + cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_iterator_new(&iter, diff)); + + while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(delta != NULL); + count++; + } + + cl_assert_equal_i(GIT_ITEROVER, error); + cl_assert(delta == NULL); + cl_assert_equal_i(8, count); + + git_diff_iterator_free(iter); + git_diff_list_free(diff); +} + +void test_diff_diffiter__iterate_files_and_hunks(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + git_diff_iterator *iter; + git_diff_delta *delta; + git_diff_range *range; + const char *header; + size_t header_len; + int error, file_count = 0, hunk_count = 0; + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + + cl_git_pass(git_diff_iterator_new(&iter, diff)); + + while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(delta); + + file_count++; + + while ((error = git_diff_iterator_next_hunk( + &range, &header, &header_len, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(range); + hunk_count++; + } + } + + cl_assert_equal_i(GIT_ITEROVER, error); + cl_assert(delta == NULL); + cl_assert_equal_i(13, file_count); + cl_assert_equal_i(8, hunk_count); + + git_diff_iterator_free(iter); + git_diff_list_free(diff); +} -- cgit v1.2.1 From 1f35e89dbf6e0be8952cc4324a45fd600be5ca05 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 11 Sep 2012 12:03:33 -0700 Subject: Fix diff binary file detection In the process of adding tests for the max file size threshold (which treats files over a certain size as binary) there seem to be a number of problems in the new code with detecting binaries. This should fix those up, as well as add a test for the file size threshold stuff. Also, this un-deprecates `GIT_DIFF_LINE_ADD_EOFNL`, since I finally found a legitimate situation where it would be returned. --- tests-clar/diff/diffiter.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 56c254741..23071e48b 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -114,3 +114,88 @@ void test_diff_diffiter__iterate_files_and_hunks(void) git_diff_iterator_free(iter); git_diff_list_free(diff); } + +void test_diff_diffiter__max_size_threshold(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + git_diff_iterator *iter; + git_diff_delta *delta; + int error, file_count = 0, binary_count = 0, hunk_count = 0; + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_iterator_new(&iter, diff)); + + while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(delta); + + file_count++; + + hunk_count += git_diff_iterator_num_hunks_in_file(iter); + + assert(delta->binary == 0 || delta->binary == 1); + + binary_count += delta->binary; + } + + cl_assert_equal_i(GIT_ITEROVER, error); + cl_assert(delta == NULL); + + cl_assert_equal_i(13, file_count); + cl_assert_equal_i(0, binary_count); + cl_assert_equal_i(8, hunk_count); + + git_diff_iterator_free(iter); + git_diff_list_free(diff); + + /* try again with low file size threshold */ + + file_count = 0; + binary_count = 0; + hunk_count = 0; + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + opts.max_size = 50; /* treat anything over 50 bytes as binary! */ + + cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_iterator_new(&iter, diff)); + + while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { + cl_assert_equal_i(0, error); + cl_assert(delta); + + file_count++; + + hunk_count += git_diff_iterator_num_hunks_in_file(iter); + + assert(delta->binary == 0 || delta->binary == 1); + + binary_count += delta->binary; + } + + cl_assert_equal_i(GIT_ITEROVER, error); + cl_assert(delta == NULL); + + cl_assert_equal_i(13, file_count); + + /* Three files are over the 50 byte threshold: + * - staged_changes_file_deleted + * - staged_changes_modified_file + * - staged_new_file_modified_file + */ + cl_assert_equal_i(3, binary_count); + + cl_assert_equal_i(5, hunk_count); + + git_diff_iterator_free(iter); + git_diff_list_free(diff); + +} -- cgit v1.2.1 From 5f69a31f7d706aa5788ad9937391577a66e3c77d Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 24 Sep 2012 20:52:34 -0700 Subject: Initial implementation of new diff patch API Replacing the `git_iterator` object, this creates a simple API for accessing the "patch" for any file pair in a diff list and then gives indexed access to the hunks in the patch and the lines in the hunk. This is the initial implementation of this revised API - it is still broken, but at least builds cleanly. --- tests-clar/diff/diffiter.c | 275 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 208 insertions(+), 67 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 23071e48b..9e33d91e1 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -14,11 +14,16 @@ void test_diff_diffiter__create(void) { git_repository *repo = cl_git_sandbox_init("attr"); git_diff_list *diff; - git_diff_iterator *iter; + size_t d, num_d; cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); - git_diff_iterator_free(iter); + + num_d = git_diff_num_deltas(diff); + for (d = 0; d < num_d; ++d) { + git_diff_delta *delta; + cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); + } + git_diff_list_free(diff); } @@ -26,24 +31,22 @@ void test_diff_diffiter__iterate_files(void) { git_repository *repo = cl_git_sandbox_init("attr"); git_diff_list *diff; - git_diff_iterator *iter; - git_diff_delta *delta; - int error, count = 0; + size_t d, num_d; + int count = 0; cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); - while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); + num_d = git_diff_num_deltas(diff); + cl_assert_equal_i(6, num_d); + + for (d = 0; d < num_d; ++d) { + git_diff_delta *delta; + cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); cl_assert(delta != NULL); count++; } - - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert(delta == NULL); cl_assert_equal_i(6, count); - git_diff_iterator_free(iter); git_diff_list_free(diff); } @@ -51,24 +54,22 @@ void test_diff_diffiter__iterate_files_2(void) { git_repository *repo = cl_git_sandbox_init("status"); git_diff_list *diff; - git_diff_iterator *iter; - git_diff_delta *delta; - int error, count = 0; + size_t d, num_d; + int count = 0; cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); - while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); + num_d = git_diff_num_deltas(diff); + cl_assert_equal_i(8, num_d); + + for (d = 0; d < num_d; ++d) { + git_diff_delta *delta; + cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); cl_assert(delta != NULL); count++; } - - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert(delta == NULL); cl_assert_equal_i(8, count); - git_diff_iterator_free(iter); git_diff_list_free(diff); } @@ -77,12 +78,8 @@ void test_diff_diffiter__iterate_files_and_hunks(void) git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = {0}; git_diff_list *diff = NULL; - git_diff_iterator *iter; - git_diff_delta *delta; - git_diff_range *range; - const char *header; - size_t header_len; - int error, file_count = 0, hunk_count = 0; + size_t d, num_d; + int file_count = 0, hunk_count = 0; opts.context_lines = 3; opts.interhunk_lines = 1; @@ -90,28 +87,42 @@ void test_diff_diffiter__iterate_files_and_hunks(void) cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); + num_d = git_diff_num_deltas(diff); + + for (d = 0; d < num_d; ++d) { + git_diff_patch *patch; + git_diff_delta *delta; + size_t h, num_h; + + cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); - while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); cl_assert(delta); + cl_assert(patch); file_count++; - while ((error = git_diff_iterator_next_hunk( - &range, &header, &header_len, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); + num_h = git_diff_patch_num_hunks(patch); + + for (h = 0; h < num_h; h++) { + git_diff_range *range; + const char *header; + size_t header_len, num_l; + + cl_git_pass(git_diff_patch_get_hunk( + &range, &header, &header_len, &num_l, patch, h)); + cl_assert(range); + cl_assert(header); + hunk_count++; } + + git_diff_patch_free(patch); } - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert(delta == NULL); cl_assert_equal_i(13, file_count); cl_assert_equal_i(8, hunk_count); - git_diff_iterator_free(iter); git_diff_list_free(diff); } @@ -120,45 +131,42 @@ void test_diff_diffiter__max_size_threshold(void) git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = {0}; git_diff_list *diff = NULL; - git_diff_iterator *iter; - git_diff_delta *delta; - int error, file_count = 0, binary_count = 0, hunk_count = 0; + int file_count = 0, binary_count = 0, hunk_count = 0; + size_t d, num_d; opts.context_lines = 3; opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); + num_d = git_diff_num_deltas(diff); - while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); + for (d = 0; d < num_d; ++d) { + git_diff_patch *patch; + git_diff_delta *delta; + + cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); cl_assert(delta); + cl_assert(patch); file_count++; - - hunk_count += git_diff_iterator_num_hunks_in_file(iter); + hunk_count += git_diff_patch_num_hunks(patch); assert(delta->binary == 0 || delta->binary == 1); - binary_count += delta->binary; - } - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert(delta == NULL); + git_diff_patch_free(patch); + } cl_assert_equal_i(13, file_count); cl_assert_equal_i(0, binary_count); cl_assert_equal_i(8, hunk_count); - git_diff_iterator_free(iter); git_diff_list_free(diff); /* try again with low file size threshold */ - file_count = 0; - binary_count = 0; - hunk_count = 0; + file_count = binary_count = hunk_count = 0; opts.context_lines = 3; opts.interhunk_lines = 1; @@ -166,36 +174,169 @@ void test_diff_diffiter__max_size_threshold(void) opts.max_size = 50; /* treat anything over 50 bytes as binary! */ cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); - cl_git_pass(git_diff_iterator_new(&iter, diff)); + num_d = git_diff_num_deltas(diff); - while ((error = git_diff_iterator_next_file(&delta, iter)) != GIT_ITEROVER) { - cl_assert_equal_i(0, error); - cl_assert(delta); + for (d = 0; d < num_d; ++d) { + git_diff_patch *patch; + git_diff_delta *delta; - file_count++; + cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); - hunk_count += git_diff_iterator_num_hunks_in_file(iter); + file_count++; + hunk_count += git_diff_patch_num_hunks(patch); assert(delta->binary == 0 || delta->binary == 1); - binary_count += delta->binary; - } - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert(delta == NULL); + git_diff_patch_free(patch); + } cl_assert_equal_i(13, file_count); - /* Three files are over the 50 byte threshold: * - staged_changes_file_deleted * - staged_changes_modified_file * - staged_new_file_modified_file */ cl_assert_equal_i(3, binary_count); - cl_assert_equal_i(5, hunk_count); - git_diff_iterator_free(iter); git_diff_list_free(diff); +} + + +void test_diff_diffiter__iterate_all(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + diff_expects exp = {0}; + size_t d, num_d; + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + + num_d = git_diff_num_deltas(diff); + for (d = 0; d < num_d; ++d) { + git_diff_patch *patch; + git_diff_delta *delta; + size_t h, num_h; + + cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); + cl_assert(patch && delta); + exp.files++; + + num_h = git_diff_patch_num_hunks(patch); + for (h = 0; h < num_h; h++) { + git_diff_range *range; + const char *header; + size_t header_len, l, num_l; + + cl_git_pass(git_diff_patch_get_hunk( + &range, &header, &header_len, &num_l, patch, h)); + cl_assert(range && header); + exp.hunks++; + + for (l = 0; l < num_l; ++l) { + char origin; + const char *content; + size_t content_len; + + cl_git_pass(git_diff_patch_get_line_in_hunk( + &origin, &content, &content_len, NULL, NULL, patch, h, l)); + cl_assert(content); + exp.lines++; + } + } + + git_diff_patch_free(patch); + } + + cl_assert_equal_i(13, exp.files); + cl_assert_equal_i(8, exp.hunks); + cl_assert_equal_i(13, exp.lines); + + git_diff_list_free(diff); +} + +static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) +{ + size_t h, num_h = git_diff_patch_num_hunks(patch); + + exp->files++; + exp->hunks += num_h; + + /* let's iterate in reverse, just because we can! */ + for (h = 1; h <= num_h; ++h) + exp->lines += git_diff_patch_num_lines_in_hunk(patch, num_h - h); +} + +#define PATCH_CACHE 5 + +void test_diff_diffiter__iterate_randomly_while_saving_state(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + diff_expects exp = {0}; + git_diff_patch *patches[PATCH_CACHE]; + size_t p, d, num_d; + + memset(patches, 0, sizeof(patches)); + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + + num_d = git_diff_num_deltas(diff); + + /* To make sure that references counts work for diff and patch objects, + * this generates patches and randomly caches them. Only when the patch + * is removed from the cache are hunks and lines counted. At the end, + * there are still patches in the cache, so free the diff and try to + * process remaining patches after the diff is freed. + */ + + srand(121212); + p = rand() % PATCH_CACHE; + + for (d = 0; d < num_d; ++d) { + /* take old patch */ + git_diff_patch *patch = patches[p]; + patches[p] = NULL; + + /* cache new patch */ + cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d)); + cl_assert(patches[p] != NULL); + + /* process old patch if non-NULL */ + if (patch != NULL) { + iterate_over_patch(patch, &exp); + git_diff_patch_free(patch); + } + + p = rand() % PATCH_CACHE; + } + + /* free diff list now - refcounts should keep things safe */ + git_diff_list_free(diff); + + /* process remaining unprocessed patches */ + for (p = 0; p < PATCH_CACHE; p++) { + git_diff_patch *patch = patches[p]; + + if (patch != NULL) { + iterate_over_patch(patch, &exp); + git_diff_patch_free(patch); + } + } + /* hopefully it all still added up right */ + cl_assert_equal_i(13, exp.files); + cl_assert_equal_i(8, exp.hunks); + cl_assert_equal_i(13, exp.lines); } -- cgit v1.2.1 From 642863086575a61b3ed0bbbe909f4f07d87ff9db Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 25 Sep 2012 10:48:50 -0700 Subject: Fix bugs in new diff patch code This fixes all the bugs in the new diff patch code. The only really interesting one is that when we merge two diffs, we now have to actually exclude diff delta records that are not supposed to be tracked, as opposed to before where they could be included because they would be skipped silently by `git_diff_foreach()`. Other than that, there are just minor errors. --- tests-clar/diff/diffiter.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 9e33d91e1..4273b16dd 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -256,21 +256,23 @@ void test_diff_diffiter__iterate_all(void) cl_assert_equal_i(13, exp.files); cl_assert_equal_i(8, exp.hunks); - cl_assert_equal_i(13, exp.lines); + cl_assert_equal_i(14, exp.lines); git_diff_list_free(diff); } static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) { - size_t h, num_h = git_diff_patch_num_hunks(patch); + size_t h, num_h = git_diff_patch_num_hunks(patch), num_l; exp->files++; exp->hunks += num_h; /* let's iterate in reverse, just because we can! */ - for (h = 1; h <= num_h; ++h) - exp->lines += git_diff_patch_num_lines_in_hunk(patch, num_h - h); + for (h = 1, num_l = 0; h <= num_h; ++h) + num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h); + + exp->lines += num_l; } #define PATCH_CACHE 5 @@ -338,5 +340,5 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) /* hopefully it all still added up right */ cl_assert_equal_i(13, exp.files); cl_assert_equal_i(8, exp.hunks); - cl_assert_equal_i(13, exp.lines); + cl_assert_equal_i(14, exp.lines); } -- cgit v1.2.1 From bae957b95d59a840df72a725b06f00635471cfd8 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 25 Sep 2012 16:31:46 -0700 Subject: Add const to all shared pointers in diff API There are a lot of places where the diff API gives the user access to internal data structures and many of these were being exposed through non-const pointers. This replaces them all with const pointers for any object that the user can access but is still owned internally to the git_diff_list or git_diff_patch objects. This will probably break some bindings... Sorry! --- tests-clar/diff/diffiter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 4273b16dd..78f97fc86 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -20,7 +20,7 @@ void test_diff_diffiter__create(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - git_diff_delta *delta; + const git_diff_delta *delta; cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); } @@ -40,7 +40,7 @@ void test_diff_diffiter__iterate_files(void) cl_assert_equal_i(6, num_d); for (d = 0; d < num_d; ++d) { - git_diff_delta *delta; + const git_diff_delta *delta; cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); cl_assert(delta != NULL); count++; @@ -63,7 +63,7 @@ void test_diff_diffiter__iterate_files_2(void) cl_assert_equal_i(8, num_d); for (d = 0; d < num_d; ++d) { - git_diff_delta *delta; + const git_diff_delta *delta; cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); cl_assert(delta != NULL); count++; @@ -91,7 +91,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) for (d = 0; d < num_d; ++d) { git_diff_patch *patch; - git_diff_delta *delta; + const git_diff_delta *delta; size_t h, num_h; cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); @@ -104,7 +104,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) num_h = git_diff_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - git_diff_range *range; + const git_diff_range *range; const char *header; size_t header_len, num_l; @@ -143,7 +143,7 @@ void test_diff_diffiter__max_size_threshold(void) for (d = 0; d < num_d; ++d) { git_diff_patch *patch; - git_diff_delta *delta; + const git_diff_delta *delta; cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); cl_assert(delta); @@ -178,7 +178,7 @@ void test_diff_diffiter__max_size_threshold(void) for (d = 0; d < num_d; ++d) { git_diff_patch *patch; - git_diff_delta *delta; + const git_diff_delta *delta; cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); @@ -221,7 +221,7 @@ void test_diff_diffiter__iterate_all(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { git_diff_patch *patch; - git_diff_delta *delta; + const git_diff_delta *delta; size_t h, num_h; cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); @@ -230,7 +230,7 @@ void test_diff_diffiter__iterate_all(void) num_h = git_diff_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - git_diff_range *range; + const git_diff_range *range; const char *header; size_t header_len, l, num_l; -- cgit v1.2.1 From cc5bf359a6a56b2abd898feccf2c33dc2a5f6a3e Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 28 Sep 2012 09:08:09 -0700 Subject: Clean up Win64 warnings --- tests-clar/diff/diffiter.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 78f97fc86..f6d9bfc38 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -37,7 +37,7 @@ void test_diff_diffiter__iterate_files(void) cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); num_d = git_diff_num_deltas(diff); - cl_assert_equal_i(6, num_d); + cl_assert_equal_i(6, (int)num_d); for (d = 0; d < num_d; ++d) { const git_diff_delta *delta; @@ -60,7 +60,7 @@ void test_diff_diffiter__iterate_files_2(void) cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); num_d = git_diff_num_deltas(diff); - cl_assert_equal_i(8, num_d); + cl_assert_equal_i(8, (int)num_d); for (d = 0; d < num_d; ++d) { const git_diff_delta *delta; @@ -150,7 +150,7 @@ void test_diff_diffiter__max_size_threshold(void) cl_assert(patch); file_count++; - hunk_count += git_diff_patch_num_hunks(patch); + hunk_count += (int)git_diff_patch_num_hunks(patch); assert(delta->binary == 0 || delta->binary == 1); binary_count += delta->binary; @@ -183,7 +183,7 @@ void test_diff_diffiter__max_size_threshold(void) cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); file_count++; - hunk_count += git_diff_patch_num_hunks(patch); + hunk_count += (int)git_diff_patch_num_hunks(patch); assert(delta->binary == 0 || delta->binary == 1); binary_count += delta->binary; @@ -266,13 +266,13 @@ static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) size_t h, num_h = git_diff_patch_num_hunks(patch), num_l; exp->files++; - exp->hunks += num_h; + exp->hunks += (int)num_h; /* let's iterate in reverse, just because we can! */ for (h = 1, num_l = 0; h <= num_h; ++h) num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h); - exp->lines += num_l; + exp->lines += (int)num_l; } #define PATCH_CACHE 5 -- cgit v1.2.1 From 93cf7bb8e26a04d9bd4197c1b938cee352023f63 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 24 Oct 2012 20:56:32 -0700 Subject: Add git_diff_patch_to_str API This adds an API to generate a complete single-file patch text from a git_diff_patch object. --- tests-clar/diff/diffiter.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index f6d9bfc38..86e8d1f57 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -342,3 +342,102 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) cl_assert_equal_i(8, exp.hunks); cl_assert_equal_i(14, exp.lines); } + +/* This output is taken directly from `git diff` on the status test data */ +static const char *expected_patch_text[8] = { + /* 0 */ + "diff --git a/file_deleted b/file_deleted\n" + "deleted file mode 100644\n" + "index 5452d32..0000000\n" + "--- a/file_deleted\n" + "+++ /dev/null\n" + "@@ -1 +0,0 @@\n" + "-file_deleted\n", + /* 1 */ + "diff --git a/modified_file b/modified_file\n" + "index 452e424..0a53963 100644\n" + "--- a/modified_file\n" + "+++ b/modified_file\n" + "@@ -1 +1,2 @@\n" + " modified_file\n" + "+modified_file\n", + /* 2 */ + "diff --git a/staged_changes_file_deleted b/staged_changes_file_deleted\n" + "deleted file mode 100644\n" + "index a6be623..0000000\n" + "--- a/staged_changes_file_deleted\n" + "+++ /dev/null\n" + "@@ -1,2 +0,0 @@\n" + "-staged_changes_file_deleted\n" + "-staged_changes_file_deleted\n", + /* 3 */ + "diff --git a/staged_changes_modified_file b/staged_changes_modified_file\n" + "index 906ee77..011c344 100644\n" + "--- a/staged_changes_modified_file\n" + "+++ b/staged_changes_modified_file\n" + "@@ -1,2 +1,3 @@\n" + " staged_changes_modified_file\n" + " staged_changes_modified_file\n" + "+staged_changes_modified_file\n", + /* 4 */ + "diff --git a/staged_new_file_deleted_file b/staged_new_file_deleted_file\n" + "deleted file mode 100644\n" + "index 90b8c29..0000000\n" + "--- a/staged_new_file_deleted_file\n" + "+++ /dev/null\n" + "@@ -1 +0,0 @@\n" + "-staged_new_file_deleted_file\n", + /* 5 */ + "diff --git a/staged_new_file_modified_file b/staged_new_file_modified_file\n" + "index ed06290..8b090c0 100644\n" + "--- a/staged_new_file_modified_file\n" + "+++ b/staged_new_file_modified_file\n" + "@@ -1 +1,2 @@\n" + " staged_new_file_modified_file\n" + "+staged_new_file_modified_file\n", + /* 6 */ + "diff --git a/subdir/deleted_file b/subdir/deleted_file\n" + "deleted file mode 100644\n" + "index 1888c80..0000000\n" + "--- a/subdir/deleted_file\n" + "+++ /dev/null\n" + "@@ -1 +0,0 @@\n" + "-subdir/deleted_file\n", + /* 7 */ + "diff --git a/subdir/modified_file b/subdir/modified_file\n" + "index a619198..57274b7 100644\n" + "--- a/subdir/modified_file\n" + "+++ b/subdir/modified_file\n" + "@@ -1 +1,2 @@\n" + " subdir/modified_file\n" + "+subdir/modified_file\n" +}; + +void test_diff_diffiter__iterate_and_generate_patch_text(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_list *diff; + size_t d, num_d; + + cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + + num_d = git_diff_num_deltas(diff); + cl_assert_equal_i(8, (int)num_d); + + for (d = 0; d < num_d; ++d) { + git_diff_patch *patch; + char *text; + + cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d)); + cl_assert(patch != NULL); + + cl_git_pass(git_diff_patch_to_str(&text, patch)); + + cl_assert_equal_s(expected_patch_text[d], text); + + git__free(text); + git_diff_patch_free(patch); + } + + git_diff_list_free(diff); +} -- cgit v1.2.1 From 5735bf5e6ab4da347b601d4b85c09c5c701dc002 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 13 Nov 2012 13:58:29 -0800 Subject: Fix diff API to better parameter order The diff API is not in the parameter order one would expect from other libgit2 APIs. This fixes that. --- tests-clar/diff/diffiter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 86e8d1f57..f021d46f4 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -16,7 +16,7 @@ void test_diff_diffiter__create(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -34,7 +34,7 @@ void test_diff_diffiter__iterate_files(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(6, (int)num_d); @@ -57,7 +57,7 @@ void test_diff_diffiter__iterate_files_2(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); @@ -85,7 +85,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); num_d = git_diff_num_deltas(diff); @@ -138,7 +138,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -173,7 +173,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.max_size = 50; /* treat anything over 50 bytes as binary! */ - cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -216,7 +216,7 @@ void test_diff_diffiter__iterate_all(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -292,7 +292,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(repo, &opts, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); num_d = git_diff_num_deltas(diff); @@ -419,7 +419,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(repo, NULL, &diff)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); -- cgit v1.2.1 From bbe6dbec81d2050fb52b600bc27e2dacdc780e77 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 14 Nov 2012 23:29:48 -0800 Subject: Add explicit git_index ptr to diff and checkout A number of diff APIs and the `git_checkout_index` API take a `git_repository` object an operate on the index. This updates them to take a `git_index` pointer explicitly and only fall back on the `git_repository` index if the index input is NULL. This makes it easier to operate on a temporary index. --- tests-clar/diff/diffiter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index f021d46f4..133392c21 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -16,7 +16,7 @@ void test_diff_diffiter__create(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -34,7 +34,7 @@ void test_diff_diffiter__iterate_files(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(6, (int)num_d); @@ -57,7 +57,7 @@ void test_diff_diffiter__iterate_files_2(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); @@ -85,7 +85,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); @@ -138,7 +138,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -173,7 +173,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.max_size = 50; /* treat anything over 50 bytes as binary! */ - cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -216,7 +216,7 @@ void test_diff_diffiter__iterate_all(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -292,7 +292,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, &opts)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); @@ -419,7 +419,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL)); + cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); -- cgit v1.2.1 From 2f8d30becb4801d869188d2d46ca1512843e8698 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 29 Nov 2012 15:05:04 -0800 Subject: Deploy GIT_DIFF_OPTIONS_INIT --- tests-clar/diff/diffiter.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 133392c21..306a13eb9 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -76,7 +76,7 @@ void test_diff_diffiter__iterate_files_2(void) void test_diff_diffiter__iterate_files_and_hunks(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; size_t d, num_d; int file_count = 0, hunk_count = 0; @@ -129,7 +129,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) void test_diff_diffiter__max_size_threshold(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; int file_count = 0, binary_count = 0, hunk_count = 0; size_t d, num_d; @@ -207,7 +207,7 @@ void test_diff_diffiter__max_size_threshold(void) void test_diff_diffiter__iterate_all(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp = {0}; size_t d, num_d; @@ -280,7 +280,7 @@ static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) void test_diff_diffiter__iterate_randomly_while_saving_state(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp = {0}; git_diff_patch *patches[PATCH_CACHE]; @@ -441,3 +441,25 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_diff_list_free(diff); } + +void test_diff_diffiter__checks_options_version(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff_list *diff = NULL; + const git_error *err; + + opts.version = 0; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} + -- cgit v1.2.1 From 56c72b759c3adb92c0fdab18fccfb25fb561cd4f Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 17 Dec 2012 11:00:53 -0800 Subject: Fix diff constructor name order confusion The diff constructor functions had some confusing names, where the "old" side of the diff was coming after the "new" side. This reverses the order in the function name to make it less confusing. Specifically... * git_diff_index_to_tree becomes git_diff_tree_to_index * git_diff_workdir_to_index becomes git_diff_index_to_workdir * git_diff_workdir_to_tree becomes git_diff_tree_to_workdir --- tests-clar/diff/diffiter.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 306a13eb9..8d550ec0f 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -16,7 +16,7 @@ void test_diff_diffiter__create(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -34,7 +34,7 @@ void test_diff_diffiter__iterate_files(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(6, (int)num_d); @@ -57,7 +57,7 @@ void test_diff_diffiter__iterate_files_2(void) size_t d, num_d; int count = 0; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); @@ -85,7 +85,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); @@ -138,7 +138,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -173,7 +173,7 @@ void test_diff_diffiter__max_size_threshold(void) opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; opts.max_size = 50; /* treat anything over 50 bytes as binary! */ - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -216,7 +216,7 @@ void test_diff_diffiter__iterate_all(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { @@ -292,7 +292,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); num_d = git_diff_num_deltas(diff); @@ -419,7 +419,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_diff_list *diff; size_t d, num_d; - cl_git_pass(git_diff_workdir_to_index(&diff, repo, NULL, NULL)); + cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); num_d = git_diff_num_deltas(diff); cl_assert_equal_i(8, (int)num_d); @@ -452,13 +452,13 @@ void test_diff_diffiter__checks_options_version(void) opts.version = 0; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; - cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_fail(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); err = giterr_last(); cl_assert_equal_i(GITERR_INVALID, err->klass); giterr_clear(); opts.version = 1024; - cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + cl_git_fail(git_diff_index_to_workdir(&diff, repo, NULL, &opts)); err = giterr_last(); cl_assert_equal_i(GITERR_INVALID, err->klass); } -- cgit v1.2.1 From 71a3d27ea686845811f04314d02798b4f1745046 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 8 Feb 2013 10:06:47 -0800 Subject: Replace diff delta binary with flags Previously the git_diff_delta recorded if the delta was binary. This replaces that (with no net change in structure size) with a full set of flags. The flag values that were already in use for individual git_diff_file objects are reused for the delta flags, too (along with renaming those flags to make it clear that they are used more generally). This (a) makes things somewhat more consistent (because I was using a -1 value in the "boolean" binary field to indicate unset, whereas now I can just use the flags that are easier to understand), and (b) will make it easier for me to add some additional flags to the delta object in the future, such as marking the results of a copy/rename detection or other deltas that might want a special indicator. While making this change, I officially moved some of the flags that were internal only into the private diff header. This also allowed me to remove a gross hack in rename/copy detect code where I was overwriting the status field with an internal value. --- tests-clar/diff/diffiter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 8d550ec0f..932d720f2 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -152,8 +152,8 @@ void test_diff_diffiter__max_size_threshold(void) file_count++; hunk_count += (int)git_diff_patch_num_hunks(patch); - assert(delta->binary == 0 || delta->binary == 1); - binary_count += delta->binary; + assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0); + binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0); git_diff_patch_free(patch); } @@ -185,8 +185,8 @@ void test_diff_diffiter__max_size_threshold(void) file_count++; hunk_count += (int)git_diff_patch_num_hunks(patch); - assert(delta->binary == 0 || delta->binary == 1); - binary_count += delta->binary; + assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0); + binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0); git_diff_patch_free(patch); } -- cgit v1.2.1