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/tree.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests-clar/diff/tree.c') diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index f05c7869e..7286ee121 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -3,7 +3,7 @@ static git_repository *g_repo = NULL; static git_diff_options opts; -static git_diff_list *diff; +static git_diff *diff; static git_tree *a, *b; static diff_expects expect; @@ -22,7 +22,7 @@ void test_diff_tree__initialize(void) void test_diff_tree__cleanup(void) { - git_diff_list_free(diff); + git_diff_free(diff); git_tree_free(a); git_tree_free(b); @@ -65,7 +65,7 @@ void test_diff_tree__0(void) cl_assert_equal_i(24 + 1 + 5 + 5, expect.line_adds); cl_assert_equal_i(7 + 1, expect.line_dels); - git_diff_list_free(diff); + git_diff_free(diff); diff = NULL; memset(&expect, 0, sizeof(expect)); @@ -168,7 +168,7 @@ void test_diff_tree__options(void) cl_assert_equal_i(actual.line_adds, expected->line_adds); cl_assert_equal_i(actual.line_dels, expected->line_dels); - git_diff_list_free(diff); + git_diff_free(diff); diff = NULL; } @@ -214,7 +214,7 @@ void test_diff_tree__merge(void) const char *b_commit = "370fe9ec22"; const char *c_commit = "f5b0af1fb4f5c"; git_tree *c; - git_diff_list *diff1 = NULL, *diff2 = NULL; + git_diff *diff1 = NULL, *diff2 = NULL; g_repo = cl_git_sandbox_init("attr"); @@ -230,7 +230,7 @@ void test_diff_tree__merge(void) cl_git_pass(git_diff_merge(diff1, diff2)); - git_diff_list_free(diff2); + git_diff_free(diff2); cl_git_pass(git_diff_foreach( diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect)); @@ -247,7 +247,7 @@ void test_diff_tree__merge(void) cl_assert_equal_i(36, expect.line_adds); cl_assert_equal_i(22, expect.line_dels); - git_diff_list_free(diff1); + git_diff_free(diff1); } void test_diff_tree__larger_hunks(void) @@ -256,8 +256,8 @@ void test_diff_tree__larger_hunks(void) const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; size_t d, num_d, h, num_h, l, num_l, header_len, line_len; const git_diff_delta *delta; - git_diff_patch *patch; - const git_diff_range *range; + git_patch *patch; + const git_diff_hunk *range; const char *header, *line; char origin; @@ -273,31 +273,31 @@ void test_diff_tree__larger_hunks(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - 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); - num_h = git_diff_patch_num_hunks(patch); + num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - cl_git_pass(git_diff_patch_get_hunk( + cl_git_pass(git_patch_get_hunk( &range, &header, &header_len, &num_l, patch, h)); for (l = 0; l < num_l; ++l) { - cl_git_pass(git_diff_patch_get_line_in_hunk( + cl_git_pass(git_patch_get_line_in_hunk( &origin, &line, &line_len, NULL, NULL, patch, h, l)); cl_assert(line); } - cl_git_fail(git_diff_patch_get_line_in_hunk( + cl_git_fail(git_patch_get_line_in_hunk( &origin, &line, &line_len, NULL, NULL, patch, h, num_l)); } - cl_git_fail(git_diff_patch_get_hunk( + cl_git_fail(git_patch_get_hunk( &range, &header, &header_len, &num_l, patch, num_h)); - git_diff_patch_free(patch); + git_patch_free(patch); } - cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d)); + cl_git_fail(git_patch_from_diff(&patch, &delta, diff, num_d)); cl_assert_equal_i(2, (int)num_d); } @@ -487,7 +487,7 @@ void test_diff_tree__diff_configs(void) cl_assert_equal_i(7, expect.line_adds); cl_assert_equal_i(15, expect.line_dels); - git_diff_list_free(diff); + git_diff_free(diff); diff = NULL; set_config_int(g_repo, "diff.context", 1); @@ -507,7 +507,7 @@ void test_diff_tree__diff_configs(void) cl_assert_equal_i(7, expect.line_adds); cl_assert_equal_i(15, expect.line_dels); - git_diff_list_free(diff); + git_diff_free(diff); diff = NULL; set_config_int(g_repo, "diff.context", 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/tree.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'tests-clar/diff/tree.c') diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index 7286ee121..8231d3632 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -90,6 +90,9 @@ void test_diff_tree__0(void) git_tree_free(c); } +#define DIFF_OPTS(FLAGS, CTXT) \ + {GIT_DIFF_OPTIONS_VERSION, (FLAGS), 0, {NULL,0}, NULL, NULL, (CTXT), 1} + void test_diff_tree__options(void) { /* grabbed a couple of commit oids from the history of the attr repo */ @@ -102,16 +105,16 @@ void test_diff_tree__options(void) int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 }; git_diff_options test_options[] = { /* a vs b tests */ - { 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} }, + DIFF_OPTS(GIT_DIFF_NORMAL, 1), + DIFF_OPTS(GIT_DIFF_NORMAL, 3), + DIFF_OPTS(GIT_DIFF_REVERSE, 2), + DIFF_OPTS(GIT_DIFF_FORCE_TEXT, 2), /* c vs d tests */ - { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} }, - { 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} }, + DIFF_OPTS(GIT_DIFF_NORMAL, 3), + DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE, 3), + DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3), + DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_EOL, 3), + DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1), }; /* to generate these values: @@ -255,7 +258,6 @@ void test_diff_tree__larger_hunks(void) const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; size_t d, num_d, h, num_h, l, num_l, header_len, line_len; - const git_diff_delta *delta; git_patch *patch; const git_diff_hunk *range; const char *header, *line; @@ -273,8 +275,8 @@ void test_diff_tree__larger_hunks(void) num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { - 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); num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { @@ -297,7 +299,7 @@ void test_diff_tree__larger_hunks(void) git_patch_free(patch); } - cl_git_fail(git_patch_from_diff(&patch, &delta, diff, num_d)); + cl_git_fail(git_patch_from_diff(&patch, diff, num_d)); cl_assert_equal_i(2, (int)num_d); } -- 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/tree.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'tests-clar/diff/tree.c') diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index 8231d3632..ca2daf5fb 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -257,11 +257,10 @@ void test_diff_tree__larger_hunks(void) { const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; - size_t d, num_d, h, num_h, l, num_l, header_len, line_len; + size_t d, num_d, h, num_h, l, num_l; git_patch *patch; - const git_diff_hunk *range; - const char *header, *line; - char origin; + const git_diff_hunk *hunk; + const git_diff_line *line; g_repo = cl_git_sandbox_init("diff"); @@ -280,21 +279,17 @@ void test_diff_tree__larger_hunks(void) num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { - cl_git_pass(git_patch_get_hunk( - &range, &header, &header_len, &num_l, patch, h)); + cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h)); for (l = 0; l < num_l; ++l) { - cl_git_pass(git_patch_get_line_in_hunk( - &origin, &line, &line_len, NULL, NULL, patch, h, l)); + cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l)); cl_assert(line); } - cl_git_fail(git_patch_get_line_in_hunk( - &origin, &line, &line_len, NULL, NULL, patch, h, num_l)); + cl_git_fail(git_patch_get_line_in_hunk(&line, patch, h, num_l)); } - cl_git_fail(git_patch_get_hunk( - &range, &header, &header_len, &num_l, patch, num_h)); + cl_git_fail(git_patch_get_hunk(&hunk, &num_l, patch, num_h)); git_patch_free(patch); } -- cgit v1.2.1