summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-05-19 09:31:30 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2021-05-19 09:31:30 +0100
commit1ee3c37f48479e92f57c1a5da8c8393f4a745d13 (patch)
tree344f7a2fec6c47c9a74a1f2d69b9492f85c871cd
parent319ff349039dc73f5fe099f83f198fb65782414f (diff)
parent6b1f6e00bf7c91b3b5230e20ecb57a7d9792cee7 (diff)
downloadlibgit2-1ee3c37f48479e92f57c1a5da8c8393f4a745d13.tar.gz
Merge branch 'pr/5853'
-rw-r--r--.gitignore1
-rw-r--r--include/git2/diff.h4
-rw-r--r--src/diff_xdiff.c3
-rw-r--r--tests/diff/workdir.c35
4 files changed, 43 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 69d388f8e..1b482f038 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
/tags
CMakeSettings.json
.vs
+.idea
diff --git a/include/git2/diff.h b/include/git2/diff.h
index e10555595..c63d93dc8 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -168,6 +168,10 @@ typedef enum {
* can apply given diff information to binary files.
*/
GIT_DIFF_SHOW_BINARY = (1u << 30),
+
+ /** Ignore blank lines */
+ GIT_DIFF_IGNORE_BLANK_LINES = (1u << 31),
+
} git_diff_option_t;
/**
diff --git a/src/diff_xdiff.c b/src/diff_xdiff.c
index 8622623af..278e2be36 100644
--- a/src/diff_xdiff.c
+++ b/src/diff_xdiff.c
@@ -258,5 +258,8 @@ void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
if (flags & GIT_DIFF_MINIMAL)
xo->params.flags |= XDF_NEED_MINIMAL;
+ if (flags & GIT_DIFF_IGNORE_BLANK_LINES)
+ xo->params.flags |= XDF_IGNORE_BLANK_LINES;
+
xo->callback.outf = git_xdiff_cb;
}
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index f2404958e..00c52ff1b 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -2203,3 +2203,38 @@ void test_diff_workdir__order(void)
git_diff_free(diff);
git_tree_free(tree);
}
+
+void test_diff_workdir__ignore_blank_lines(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff *diff;
+ git_patch *patch;
+ git_buf buf = GIT_BUF_INIT;
+
+ g_repo = cl_git_sandbox_init("rebase");
+ 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");
+
+ /* Perform the diff normally */
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&buf, patch));
+
+ 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);
+
+ git_buf_dispose(&buf);
+ git_patch_free(patch);
+ git_diff_free(diff);
+
+ /* Perform the diff ignoring blank lines */
+ opts.flags |= GIT_DIFF_IGNORE_BLANK_LINES;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&buf, patch));
+
+ 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);
+
+ git_buf_dispose(&buf);
+ git_patch_free(patch);
+ git_diff_free(diff);
+}