Commit 29f9186d by yorah

diff: make inter-hunk-context default value git-compliant

Default in git core is 0, not 3
parent e560aa8f
...@@ -60,7 +60,7 @@ enum { ...@@ -60,7 +60,7 @@ enum {
typedef struct { typedef struct {
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */ uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
uint16_t context_lines; /**< defaults to 3 */ uint16_t context_lines; /**< defaults to 3 */
uint16_t interhunk_lines; /**< defaults to 3 */ uint16_t interhunk_lines; /**< defaults to 0 */
char *old_prefix; /**< defaults to "a" */ char *old_prefix; /**< defaults to "a" */
char *new_prefix; /**< defaults to "b" */ char *new_prefix; /**< defaults to "b" */
git_strarray pathspec; /**< defaults to show all paths */ git_strarray pathspec; /**< defaults to show all paths */
......
...@@ -212,7 +212,7 @@ static void setup_xdiff_options( ...@@ -212,7 +212,7 @@ static void setup_xdiff_options(
cfg->ctxlen = cfg->ctxlen =
(!opts || !opts->context_lines) ? 3 : opts->context_lines; (!opts || !opts->context_lines) ? 3 : opts->context_lines;
cfg->interhunkctxlen = cfg->interhunkctxlen =
(!opts || !opts->interhunk_lines) ? 3 : opts->interhunk_lines; (!opts) ? 0 : opts->interhunk_lines;
if (!opts) if (!opts)
return; return;
......
...@@ -14,13 +14,13 @@ void test_diff_blob__initialize(void) ...@@ -14,13 +14,13 @@ void test_diff_blob__initialize(void)
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.context_lines = 1; opts.context_lines = 1;
opts.interhunk_lines = 1; opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
/* tests/resources/attr/root_test4.txt */ /* tests/resources/attr/root_test4.txt */
cl_git_pass(git_oid_fromstrn(&oid, "fe773770c5a6", 12)); cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8));
cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 6)); cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 4));
/* alien.png */ /* alien.png */
cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8)); cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8));
...@@ -54,6 +54,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -54,6 +54,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* Doing the equivalent of a `git diff -U1` on these files */ /* Doing the equivalent of a `git diff -U1` on these files */
/* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -67,6 +68,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -67,6 +68,7 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 5); cl_assert(expected.line_adds == 5);
cl_assert(expected.line_dels == 0); cl_assert(expected.line_dels == 0);
/* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -81,6 +83,7 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -81,6 +83,7 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 9); cl_assert(expected.line_adds == 9);
cl_assert(expected.line_dels == 3); cl_assert(expected.line_dels == 3);
/* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -95,8 +98,6 @@ void test_diff_blob__can_compare_text_blobs(void) ...@@ -95,8 +98,6 @@ void test_diff_blob__can_compare_text_blobs(void)
cl_assert(expected.line_adds == 12); cl_assert(expected.line_adds == 12);
cl_assert(expected.line_dels == 1); cl_assert(expected.line_dels == 1);
opts.context_lines = 1;
memset(&expected, 0, sizeof(expected)); memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs( cl_git_pass(git_diff_blobs(
c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn)); c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
...@@ -252,3 +253,62 @@ void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void) ...@@ -252,3 +253,62 @@ void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
assert_binary_blobs_comparison(expected); assert_binary_blobs_comparison(expected);
} }
/*
* $ git diff fe773770 a0f7217
* diff --git a/fe773770 b/a0f7217
* index fe77377..a0f7217 100644
* --- a/fe773770
* +++ b/a0f7217
* @@ -1,6 +1,6 @@
* Here is some stuff at the start
*
* -This should go in one hunk
* +This should go in one hunk (first)
*
* Some additional lines
*
* @@ -8,7 +8,7 @@ Down here below the other lines
*
* With even more at the end
*
* -Followed by a second hunk of stuff
* +Followed by a second hunk of stuff (second)
*
* That happens down here
*/
void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void)
{
git_blob *old_d;
git_oid old_d_oid;
opts.context_lines = 3;
/* tests/resources/attr/root_test1 from commit f5b0af1 */
cl_git_pass(git_oid_fromstrn(&old_d_oid, "fe773770", 8));
cl_git_pass(git_blob_lookup_prefix(&old_d, g_repo, &old_d_oid, 4));
/* Test with default inter-hunk-context (not set) => default is 0 */
cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
cl_assert(expected.hunks == 2);
/* Test with inter-hunk-context explicitly set to 0 */
opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
cl_assert(expected.hunks == 2);
/* Test with inter-hunk-context explicitly set to 1 */
opts.interhunk_lines = 1;
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
old_d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
cl_assert(expected.hunks == 1);
git_blob_free(old_d);
}
...@@ -312,7 +312,7 @@ static const char *expected_index_oids_0[] = { ...@@ -312,7 +312,7 @@ static const char *expected_index_oids_0[] = {
"45141a79a77842c59a63229403220a4e4be74e3d", "45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d", "4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e", "108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"fe773770c5a6cc7185580c9204b1ff18a33ff3fc", "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249", "3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
...@@ -343,7 +343,7 @@ static const char *expected_index_oids_range[] = { ...@@ -343,7 +343,7 @@ static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d", "45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d", "4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e", "108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"fe773770c5a6cc7185580c9204b1ff18a33ff3fc", "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
}; };
void test_diff_iterator__index_range(void) void test_diff_iterator__index_range(void)
......
...@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6 ...@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status 217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
...@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6 ...@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status 217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911
Here is some stuff at the start Here is some stuff at the start
This should go in one hunk This should go in one hunk (first)
Some additional lines Some additional lines
...@@ -8,7 +8,7 @@ Down here below the other lines ...@@ -8,7 +8,7 @@ Down here below the other lines
With even more at the end With even more at the end
Followed by a second hunk of stuff Followed by a second hunk of stuff (second)
That happens down here That happens down here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment