summaryrefslogtreecommitdiff
path: root/tests-clar/diff/tree.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-10-22 11:55:54 -0700
committerVicent Martí <vicent@github.com>2013-10-22 11:55:54 -0700
commit1c74686e05c41c30944173bacec3a8312f08cbb5 (patch)
tree92f55460acf0944b00ff8d7a4500f10633351a4a /tests-clar/diff/tree.c
parent98fec8a937b93c6a6a0ad35ccd04af4cfeae1767 (diff)
parent7ce60099eec2442cc5428a830b88d51e8f9c1d75 (diff)
downloadlibgit2-1c74686e05c41c30944173bacec3a8312f08cbb5.tar.gz
Merge pull request #1897 from libgit2/split-patch-from-diff
RFC: Proposed reworking of diff APIs
Diffstat (limited to 'tests-clar/diff/tree.c')
-rw-r--r--tests-clar/diff/tree.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index f05c7869e..ca2daf5fb 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));
@@ -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:
@@ -168,7 +171,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 +217,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 +233,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,19 +250,17 @@ 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)
{
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_diff_patch *patch;
- const git_diff_range *range;
- const char *header, *line;
- char origin;
+ size_t d, num_d, h, num_h, l, num_l;
+ git_patch *patch;
+ const git_diff_hunk *hunk;
+ const git_diff_line *line;
g_repo = cl_git_sandbox_init("diff");
@@ -273,31 +274,27 @@ 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_assert(patch && delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ cl_assert(patch);
- 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(
- &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_diff_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_diff_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_diff_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_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, diff, num_d));
cl_assert_equal_i(2, (int)num_d);
}
@@ -487,7 +484,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 +504,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);