Commit 29f9186d1b772994f65bb87ac88180d7d9d4141b

yorah 2012-07-02T11:18:01

diff: make inter-hunk-context default value git-compliant Default in git core is 0, not 3

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 @@
+x510E}?΀;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