Skip to content

Commit 1ee3c37

Browse files
committed
Merge branch 'pr/5853'
2 parents 319ff34 + 6b1f6e0 commit 1ee3c37

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/tags
66
CMakeSettings.json
77
.vs
8+
.idea

include/git2/diff.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ typedef enum {
168168
* can apply given diff information to binary files.
169169
*/
170170
GIT_DIFF_SHOW_BINARY = (1u << 30),
171+
172+
/** Ignore blank lines */
173+
GIT_DIFF_IGNORE_BLANK_LINES = (1u << 31),
174+
171175
} git_diff_option_t;
172176

173177
/**

src/diff_xdiff.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,8 @@ void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
258258
if (flags & GIT_DIFF_MINIMAL)
259259
xo->params.flags |= XDF_NEED_MINIMAL;
260260

261+
if (flags & GIT_DIFF_IGNORE_BLANK_LINES)
262+
xo->params.flags |= XDF_IGNORE_BLANK_LINES;
263+
261264
xo->callback.outf = git_xdiff_cb;
262265
}

tests/diff/workdir.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,3 +2203,38 @@ void test_diff_workdir__order(void)
22032203
git_diff_free(diff);
22042204
git_tree_free(tree);
22052205
}
2206+
2207+
void test_diff_workdir__ignore_blank_lines(void)
2208+
{
2209+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
2210+
git_diff *diff;
2211+
git_patch *patch;
2212+
git_buf buf = GIT_BUF_INIT;
2213+
2214+
g_repo = cl_git_sandbox_init("rebase");
2215+
cl_git_rewritefile("rebase/gravy.txt", "GRAVY SOUP.\n\n\nGet eight pounds of coarse lean beef--wash it clean and lay it in your\n\npot, put in the same ingredients as for the shin soup, with the same\nquantity of water, and follow the process directed for that. Strain the\nsoup through a sieve, and serve it up clear, with nothing more than\ntoasted bread in it; two table-spoonsful of mushroom catsup will add a\nfine flavour to the soup!\n");
2216+
2217+
/* Perform the diff normally */
2218+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
2219+
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
2220+
cl_git_pass(git_patch_to_buf(&buf, patch));
2221+
2222+
cl_assert_equal_s("diff --git a/gravy.txt b/gravy.txt\nindex c4e6cca..3c617e6 100644\n--- a/gravy.txt\n+++ b/gravy.txt\n@@ -1,8 +1,10 @@\n GRAVY SOUP.\n \n+\n Get eight pounds of coarse lean beef--wash it clean and lay it in your\n+\n pot, put in the same ingredients as for the shin soup, with the same\n quantity of water, and follow the process directed for that. Strain the\n soup through a sieve, and serve it up clear, with nothing more than\n toasted bread in it; two table-spoonsful of mushroom catsup will add a\n-fine flavour to the soup.\n+fine flavour to the soup!\n", buf.ptr);
2223+
2224+
git_buf_dispose(&buf);
2225+
git_patch_free(patch);
2226+
git_diff_free(diff);
2227+
2228+
/* Perform the diff ignoring blank lines */
2229+
opts.flags |= GIT_DIFF_IGNORE_BLANK_LINES;
2230+
2231+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
2232+
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
2233+
cl_git_pass(git_patch_to_buf(&buf, patch));
2234+
2235+
cl_assert_equal_s("diff --git a/gravy.txt b/gravy.txt\nindex c4e6cca..3c617e6 100644\n--- a/gravy.txt\n+++ b/gravy.txt\n@@ -5,4 +7,4 @@ pot, put in the same ingredients as for the shin soup, with the same\n quantity of water, and follow the process directed for that. Strain the\n soup through a sieve, and serve it up clear, with nothing more than\n toasted bread in it; two table-spoonsful of mushroom catsup will add a\n-fine flavour to the soup.\n+fine flavour to the soup!\n", buf.ptr);
2236+
2237+
git_buf_dispose(&buf);
2238+
git_patch_free(patch);
2239+
git_diff_free(diff);
2240+
}

0 commit comments

Comments
 (0)