mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 23:26:39 +00:00
Merge pull request #797 from yorah/fix/inter-hunk-context
diff: make inter-hunk-context default value git-compliant
This commit is contained in:
commit
19017a24e3
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
Binary file not shown.
@ -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
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
x<01><>Kj1D<><44>)zol<6F>i<EFBFBD><69> _"hi<68>K2<4B>L<EFBFBD><4C>G!7Ȫ<05><><EFBFBD>J<EFBFBD>,<2C><><EFBFBD>E<EFBFBD>PX<50><58>D<EFBFBD><44>S<EFBFBD><53> ] /)<29><>}<7D><>/<2F><>Uw<55>R<EFBFBD><52>. <09>j<EFBFBD><6A><13><>p<EFBFBD><70><EFBFBD><EFBFBD>#<23><>#:?<3F><>:|<7C><>;<3B><>F9<46>܋<EFBFBD>r=_<0B><>)<29><>ơ<>N/<2F><>A[<5B><>l<EFBFBD><6C>!<21>q<EFBFBD><71>}<7D><><EFBFBD><15><Lfx4<78>H\<5C><>\<5C><>q֏cj<63><6A><EFBFBD><EFBFBD><04>T<EFBFBD>
|
@ -0,0 +1 @@
|
||||
x5Ž1Â0E™}Š?–΀;•˜Sâ<53>ˆÔ®’”ŠÛ“Ðv´ýߢ8ŸO‡'FÈÈ:2r™<72>ƒ)(¾
&¢Þ·«×9Z¼A Âð³¼Ñ¹<C391>r9Ýl¬
%¨˜ˆ„3ÑE<17>o‚<6F>£.ÿVÕi<BñàF©MÌb‰®+ÂÙŸ*vµªÛþìÖmõ÷¾¢ÞLK†ÝD?+N
|
@ -1 +1 @@
|
||||
24fa9a9fc4e202313e24b648087495441dab432b
|
||||
8d0b9df9bd30be7910ddda60548d485bc302b911
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user