diff: make inter-hunk-context default value git-compliant Default in git core is 0, not 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
diff --git a/include/git2/diff.h b/include/git2/diff.h
index d4d0eac..edec995 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -60,7 +60,7 @@ enum {
typedef struct {
uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
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 *new_prefix; /**< defaults to "b" */
git_strarray pathspec; /**< defaults to show all paths */
diff --git a/src/diff_output.c b/src/diff_output.c
index 92f7f8f..f6650b3 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -212,7 +212,7 @@ static void setup_xdiff_options(
cfg->ctxlen =
(!opts || !opts->context_lines) ? 3 : opts->context_lines;
cfg->interhunkctxlen =
- (!opts || !opts->interhunk_lines) ? 3 : opts->interhunk_lines;
+ (!opts) ? 0 : opts->interhunk_lines;
if (!opts)
return;
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index 6d7ad41..5d3ab8d 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -14,13 +14,13 @@ void test_diff_blob__initialize(void)
memset(&opts, 0, sizeof(opts));
opts.context_lines = 1;
- opts.interhunk_lines = 1;
+ opts.interhunk_lines = 0;
memset(&expected, 0, sizeof(expected));
/* tests/resources/attr/root_test4.txt */
- cl_git_pass(git_oid_fromstrn(&oid, "fe773770c5a6", 12));
- cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 6));
+ cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8));
+ cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 4));
/* alien.png */
cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8));
@@ -54,6 +54,7 @@ void test_diff_blob__can_compare_text_blobs(void)
/* Doing the equivalent of a `git diff -U1` on these files */
+ /* diff on tests/resources/attr/root_test1 */
cl_git_pass(git_diff_blobs(
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)
cl_assert(expected.line_adds == 5);
cl_assert(expected.line_dels == 0);
+ /* diff on tests/resources/attr/root_test2 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
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)
cl_assert(expected.line_adds == 9);
cl_assert(expected.line_dels == 3);
+ /* diff on tests/resources/attr/root_test3 */
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
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)
cl_assert(expected.line_adds == 12);
cl_assert(expected.line_dels == 1);
- opts.context_lines = 1;
-
memset(&expected, 0, sizeof(expected));
cl_git_pass(git_diff_blobs(
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)
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);
+}
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index eee8481..c27d3fa 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -312,7 +312,7 @@ static const char *expected_index_oids_0[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
@@ -343,7 +343,7 @@ static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
- "fe773770c5a6cc7185580c9204b1ff18a33ff3fc",
+ "a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
void test_diff_iterator__index_range(void)
diff --git a/tests-clar/resources/attr/.gitted/index b/tests-clar/resources/attr/.gitted/index
index 1d60eab..943e224 100644
Binary files a/tests-clar/resources/attr/.gitted/index and b/tests-clar/resources/attr/.gitted/index differ
diff --git a/tests-clar/resources/attr/.gitted/logs/HEAD b/tests-clar/resources/attr/.gitted/logs/HEAD
index 73f00f3..8ece39f 100644
--- a/tests-clar/resources/attr/.gitted/logs/HEAD
+++ b/tests-clar/resources/attr/.gitted/logs/HEAD
@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
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
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
diff --git a/tests-clar/resources/attr/.gitted/logs/refs/heads/master b/tests-clar/resources/attr/.gitted/logs/refs/heads/master
index 73f00f3..8ece39f 100644
--- a/tests-clar/resources/attr/.gitted/logs/refs/heads/master
+++ b/tests-clar/resources/attr/.gitted/logs/refs/heads/master
@@ -6,3 +6,4 @@ a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6
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
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
diff --git a/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512 b/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512
new file mode 100644
index 0000000..e49c94a
Binary files /dev/null and b/tests-clar/resources/attr/.gitted/objects/16/983da6643656bb44c43965ecb6855c6d574512 differ
diff --git a/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911 b/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911
new file mode 100644
index 0000000..3dcf088
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/8d/0b9df9bd30be7910ddda60548d485bc302b911
@@ -0,0 +1 @@
+xKj1D)zoli _"hiK2LG!7ȪJ,EPXDS ] /)}/UwR. jp##:?:|;F9܋r=_)ơN/A[l!q}<Lfx4H\\q֏cjT
\ No newline at end of file
diff --git a/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b b/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b
new file mode 100644
index 0000000..985c2e2
--- /dev/null
+++ b/tests-clar/resources/attr/.gitted/objects/a0/f7217ae99f5ac3e88534f5cea267febc5fa85b
@@ -0,0 +1 @@
+x510E}?;S␈Ԯۓv8O'F:2r)(
&9ZAѹr9l
%3Eo.Vi<BFMb+*vmLKݭD?+N
\ No newline at end of file
diff --git a/tests-clar/resources/attr/.gitted/refs/heads/master b/tests-clar/resources/attr/.gitted/refs/heads/master
index 8768776..b3abfff 100644
--- a/tests-clar/resources/attr/.gitted/refs/heads/master
+++ b/tests-clar/resources/attr/.gitted/refs/heads/master
@@ -1 +1 @@
-24fa9a9fc4e202313e24b648087495441dab432b
+8d0b9df9bd30be7910ddda60548d485bc302b911
diff --git a/tests-clar/resources/attr/root_test4.txt b/tests-clar/resources/attr/root_test4.txt
index fe77377..a0f7217 100644
--- a/tests-clar/resources/attr/root_test4.txt
+++ b/tests-clar/resources/attr/root_test4.txt
@@ -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