From 3ff1d123736e5686fb9ec16e65828d5b8ffa2b30 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 11 Oct 2013 14:51:54 -0700 Subject: Rename diff objects and split patch.h This makes no functional change to diff but renames a couple of the objects and splits the new git_patch (formerly git_diff_patch) into a new header file. --- tests-clar/diff/diffiter.c | 110 ++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 55 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index ea5908475..48b56e20e 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -13,7 +13,7 @@ void test_diff_diffiter__cleanup(void) void test_diff_diffiter__create(void) { git_repository *repo = cl_git_sandbox_init("attr"); - git_diff_list *diff; + git_diff *diff; size_t d, num_d; cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); @@ -21,16 +21,16 @@ void test_diff_diffiter__create(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { const git_diff_delta *delta; - cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); } - git_diff_list_free(diff); + git_diff_free(diff); } void test_diff_diffiter__iterate_files_1(void) { git_repository *repo = cl_git_sandbox_init("attr"); - git_diff_list *diff; + git_diff *diff; size_t d, num_d; diff_expects exp = { 0 }; @@ -40,20 +40,20 @@ void test_diff_diffiter__iterate_files_1(void) for (d = 0; d < num_d; ++d) { const git_diff_delta *delta; - cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); cl_assert(delta != NULL); diff_file_cb(delta, (float)d / (float)num_d, &exp); } cl_assert_equal_sz(6, exp.files); - git_diff_list_free(diff); + git_diff_free(diff); } void test_diff_diffiter__iterate_files_2(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_list *diff; + git_diff *diff; size_t d, num_d; int count = 0; @@ -64,20 +64,20 @@ void test_diff_diffiter__iterate_files_2(void) for (d = 0; d < num_d; ++d) { const git_diff_delta *delta; - cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); cl_assert(delta != NULL); count++; } cl_assert_equal_i(8, count); - git_diff_list_free(diff); + git_diff_free(diff); } void test_diff_diffiter__iterate_files_and_hunks(void) { git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; + git_diff *diff = NULL; size_t d, num_d; int file_count = 0, hunk_count = 0; @@ -90,25 +90,25 @@ void test_diff_diffiter__iterate_files_and_hunks(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - git_diff_patch *patch; + git_patch *patch; const git_diff_delta *delta; size_t h, num_h; - cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); cl_assert(delta); cl_assert(patch); file_count++; - num_h = git_diff_patch_num_hunks(patch); + num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - const git_diff_range *range; + const git_diff_hunk *range; const char *header; size_t header_len, num_l; - cl_git_pass(git_diff_patch_get_hunk( + cl_git_pass(git_patch_get_hunk( &range, &header, &header_len, &num_l, patch, h)); cl_assert(range); @@ -117,20 +117,20 @@ void test_diff_diffiter__iterate_files_and_hunks(void) hunk_count++; } - git_diff_patch_free(patch); + git_patch_free(patch); } cl_assert_equal_i(13, file_count); cl_assert_equal_i(8, hunk_count); - git_diff_list_free(diff); + git_diff_free(diff); } void test_diff_diffiter__max_size_threshold(void) { git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; + git_diff *diff = NULL; int file_count = 0, binary_count = 0, hunk_count = 0; size_t d, num_d; @@ -142,27 +142,27 @@ void test_diff_diffiter__max_size_threshold(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - git_diff_patch *patch; + git_patch *patch; const git_diff_delta *delta; - cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); cl_assert(delta); cl_assert(patch); file_count++; - hunk_count += (int)git_diff_patch_num_hunks(patch); + hunk_count += (int)git_patch_num_hunks(patch); 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); + git_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_list_free(diff); + git_diff_free(diff); /* try again with low file size threshold */ @@ -177,18 +177,18 @@ void test_diff_diffiter__max_size_threshold(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - git_diff_patch *patch; + git_patch *patch; const git_diff_delta *delta; - cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); file_count++; - hunk_count += (int)git_diff_patch_num_hunks(patch); + hunk_count += (int)git_patch_num_hunks(patch); 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); + git_patch_free(patch); } cl_assert_equal_i(13, file_count); @@ -200,7 +200,7 @@ void test_diff_diffiter__max_size_threshold(void) cl_assert_equal_i(3, binary_count); cl_assert_equal_i(5, hunk_count); - git_diff_list_free(diff); + git_diff_free(diff); } @@ -208,7 +208,7 @@ void test_diff_diffiter__iterate_all(void) { git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; + git_diff *diff = NULL; diff_expects exp = {0}; size_t d, num_d; @@ -220,21 +220,21 @@ 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_patch *patch; const git_diff_delta *delta; size_t h, num_h; - cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); cl_assert(patch && delta); exp.files++; - num_h = git_diff_patch_num_hunks(patch); + num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - const git_diff_range *range; + const git_diff_hunk *range; const char *header; size_t header_len, l, num_l; - cl_git_pass(git_diff_patch_get_hunk( + cl_git_pass(git_patch_get_hunk( &range, &header, &header_len, &num_l, patch, h)); cl_assert(range && header); exp.hunks++; @@ -244,33 +244,33 @@ void test_diff_diffiter__iterate_all(void) const char *content; size_t content_len; - cl_git_pass(git_diff_patch_get_line_in_hunk( + cl_git_pass(git_patch_get_line_in_hunk( &origin, &content, &content_len, NULL, NULL, patch, h, l)); cl_assert(content); exp.lines++; } } - git_diff_patch_free(patch); + git_patch_free(patch); } cl_assert_equal_i(13, exp.files); cl_assert_equal_i(8, exp.hunks); cl_assert_equal_i(14, exp.lines); - git_diff_list_free(diff); + git_diff_free(diff); } -static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) +static void iterate_over_patch(git_patch *patch, diff_expects *exp) { - size_t h, num_h = git_diff_patch_num_hunks(patch), num_l; + size_t h, num_h = git_patch_num_hunks(patch), num_l; exp->files++; 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); + num_l += git_patch_num_lines_in_hunk(patch, num_h - h); exp->lines += (int)num_l; } @@ -281,9 +281,9 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) { git_repository *repo = cl_git_sandbox_init("status"); git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; + git_diff *diff = NULL; diff_expects exp = {0}; - git_diff_patch *patches[PATCH_CACHE]; + git_patch *patches[PATCH_CACHE]; size_t p, d, num_d; memset(patches, 0, sizeof(patches)); @@ -308,32 +308,32 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) for (d = 0; d < num_d; ++d) { /* take old patch */ - git_diff_patch *patch = patches[p]; + git_patch *patch = patches[p]; patches[p] = NULL; /* cache new patch */ - cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d)); + cl_git_pass(git_patch_from_diff(&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); + git_patch_free(patch); } p = rand() % PATCH_CACHE; } /* free diff list now - refcounts should keep things safe */ - git_diff_list_free(diff); + git_diff_free(diff); /* process remaining unprocessed patches */ for (p = 0; p < PATCH_CACHE; p++) { - git_diff_patch *patch = patches[p]; + git_patch *patch = patches[p]; if (patch != NULL) { iterate_over_patch(patch, &exp); - git_diff_patch_free(patch); + git_patch_free(patch); } } @@ -416,7 +416,7 @@ static const char *expected_patch_text[8] = { void test_diff_diffiter__iterate_and_generate_patch_text(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_list *diff; + git_diff *diff; size_t d, num_d; cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL)); @@ -425,28 +425,28 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) cl_assert_equal_i(8, (int)num_d); for (d = 0; d < num_d; ++d) { - git_diff_patch *patch; + git_patch *patch; char *text; - cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, NULL, diff, d)); cl_assert(patch != NULL); - cl_git_pass(git_diff_patch_to_str(&text, patch)); + cl_git_pass(git_patch_to_str(&text, patch)); cl_assert_equal_s(expected_patch_text[d], text); git__free(text); - git_diff_patch_free(patch); + git_patch_free(patch); } - git_diff_list_free(diff); + git_diff_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; + git_diff *diff = NULL; const git_error *err; opts.version = 0; -- cgit v1.2.1 From 10672e3e455eba2d4ca983070ed427caeeb24a6f Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 15 Oct 2013 15:10:07 -0700 Subject: Diff API cleanup This lays groundwork for separating formatting options from diff creation options. This groups the formatting flags separately from the diff list creation flags and reorders the options. This also tweaks some APIs to further separate code that uses patches from code that just looks at git_diffs. --- tests-clar/diff/diffiter.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 48b56e20e..1a1e5dfc3 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -20,10 +20,12 @@ void test_diff_diffiter__create(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - const git_diff_delta *delta; - cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); + const git_diff_delta *delta = git_diff_get_delta(diff, d); + cl_assert(delta != NULL); } + cl_assert(!git_diff_get_delta(diff, num_d)); + git_diff_free(diff); } @@ -39,8 +41,7 @@ void test_diff_diffiter__iterate_files_1(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - const git_diff_delta *delta; - cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); + const git_diff_delta *delta = git_diff_get_delta(diff, d); cl_assert(delta != NULL); diff_file_cb(delta, (float)d / (float)num_d, &exp); @@ -63,8 +64,7 @@ void test_diff_diffiter__iterate_files_2(void) cl_assert_equal_i(8, (int)num_d); for (d = 0; d < num_d; ++d) { - const git_diff_delta *delta; - cl_git_pass(git_patch_from_diff(NULL, &delta, diff, d)); + const git_diff_delta *delta = git_diff_get_delta(diff, d); cl_assert(delta != NULL); count++; } @@ -91,12 +91,9 @@ void test_diff_diffiter__iterate_files_and_hunks(void) for (d = 0; d < num_d; ++d) { git_patch *patch; - const git_diff_delta *delta; size_t h, num_h; - cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); - - cl_assert(delta); + cl_git_pass(git_patch_from_diff(&patch, diff, d)); cl_assert(patch); file_count++; @@ -145,9 +142,10 @@ void test_diff_diffiter__max_size_threshold(void) git_patch *patch; const git_diff_delta *delta; - cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); - cl_assert(delta); + cl_git_pass(git_patch_from_diff(&patch, diff, d)); cl_assert(patch); + delta = git_patch_get_delta(patch); + cl_assert(delta); file_count++; hunk_count += (int)git_patch_num_hunks(patch); @@ -180,7 +178,8 @@ void test_diff_diffiter__max_size_threshold(void) git_patch *patch; const git_diff_delta *delta; - cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, diff, d)); + delta = git_patch_get_delta(patch); file_count++; hunk_count += (int)git_patch_num_hunks(patch); @@ -221,11 +220,10 @@ void test_diff_diffiter__iterate_all(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { git_patch *patch; - const git_diff_delta *delta; size_t h, num_h; - cl_git_pass(git_patch_from_diff(&patch, &delta, diff, d)); - cl_assert(patch && delta); + cl_git_pass(git_patch_from_diff(&patch, diff, d)); + cl_assert(patch); exp.files++; num_h = git_patch_num_hunks(patch); @@ -312,7 +310,7 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void) patches[p] = NULL; /* cache new patch */ - cl_git_pass(git_patch_from_diff(&patches[p], NULL, diff, d)); + cl_git_pass(git_patch_from_diff(&patches[p], diff, d)); cl_assert(patches[p] != NULL); /* process old patch if non-NULL */ @@ -428,7 +426,7 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_patch *patch; char *text; - cl_git_pass(git_patch_from_diff(&patch, NULL, diff, d)); + cl_git_pass(git_patch_from_diff(&patch, diff, d)); cl_assert(patch != NULL); cl_git_pass(git_patch_to_str(&text, patch)); -- cgit v1.2.1 From 3b5f795446601868d52d09ebac70ae3b7aee157a Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 21 Oct 2013 13:42:42 -0700 Subject: Create git_diff_line and extend git_diff_hunk Instead of having functions with so very many parameters to pass hunk and line data, this takes the existing git_diff_hunk struct and extends it with more hunk data, plus adds a git_diff_line. Those structs are used to pass back hunk and line data instead of the old APIs that took tons of parameters. Some work that was previously only being done for git_diff_patch creation (scanning the diff content for exact line counts) is now done for all callbacks, but the performance difference should not be noticable. --- tests-clar/diff/diffiter.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'tests-clar/diff/diffiter.c') diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 1a1e5dfc3..f886e1baa 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -101,15 +101,10 @@ void test_diff_diffiter__iterate_files_and_hunks(void) num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - const git_diff_hunk *range; - const char *header; - size_t header_len, num_l; - - cl_git_pass(git_patch_get_hunk( - &range, &header, &header_len, &num_l, patch, h)); + const git_diff_hunk *hunk; - cl_assert(range); - cl_assert(header); + cl_git_pass(git_patch_get_hunk(&hunk, NULL, patch, h)); + cl_assert(hunk); hunk_count++; } @@ -229,22 +224,17 @@ void test_diff_diffiter__iterate_all(void) num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { const git_diff_hunk *range; - const char *header; - size_t header_len, l, num_l; + size_t l, num_l; - cl_git_pass(git_patch_get_hunk( - &range, &header, &header_len, &num_l, patch, h)); - cl_assert(range && header); + cl_git_pass(git_patch_get_hunk(&range, &num_l, patch, h)); + cl_assert(range); exp.hunks++; for (l = 0; l < num_l; ++l) { - char origin; - const char *content; - size_t content_len; + const git_diff_line *line; - cl_git_pass(git_patch_get_line_in_hunk( - &origin, &content, &content_len, NULL, NULL, patch, h, l)); - cl_assert(content); + cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l)); + cl_assert(line && line->content); exp.lines++; } } -- cgit v1.2.1