diff options
28 files changed, 31 insertions, 4 deletions
diff --git a/include/git2/blame.h b/include/git2/blame.h index 73f6cf979..f42c81552 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -47,6 +47,8 @@ typedef enum { * to canonical real names and email addresses. The mailmap will be read * from the working directory, or HEAD in a bare repository. */ GIT_BLAME_USE_MAILMAP = (1<<5), + /** Ignore whitespace differences */ + GIT_BLAME_IGNORE_WHITESPACE = (1<<6), } git_blame_flag_t; /** diff --git a/src/blame_git.c b/src/blame_git.c index a9157c4ed..073137a68 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -365,11 +365,14 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx) b->size -= trimmed - recovered; } -static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data) +static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data, git_blame_options *options) { - xpparam_t xpp = {0}; xdemitconf_t xecfg = {0}; xdemitcb_t ecb = {0}; + xpparam_t xpp = {0}; + + if (options->flags & GIT_BLAME_IGNORE_WHITESPACE) + xpp.flags |= XDF_IGNORE_WHITESPACE; xecfg.hunk_func = my_emit; ecb.priv = cb_data; @@ -409,7 +412,7 @@ static int pass_blame_to_parent( fill_origin_blob(parent, &file_p); fill_origin_blob(target, &file_o); - if (diff_hunks(file_p, file_o, &d) < 0) + if (diff_hunks(file_p, file_o, &d, &blame->options) < 0) return -1; /* The reset (i.e. anything after tlno) are the same as the parent */ diff --git a/tests/blame/simple.c b/tests/blame/simple.c index 16e7bc400..6b13cccd4 100644 --- a/tests/blame/simple.c +++ b/tests/blame/simple.c @@ -239,6 +239,24 @@ void test_blame_simple__can_restrict_lines_min(void) } /* + * $ git blame -n c.txt + * orig line no final line no + * commit V author timestamp V + * 702c7aa5 1 (Carl Schwan 2020-01-29 01:52:31 +0100 4 + */ +void test_blame_simple__can_ignore_whitespace_change(void) +{ + git_blame_options opts = GIT_BLAME_OPTIONS_INIT; + + cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git"))); + + opts.flags |= GIT_BLAME_IGNORE_WHITESPACE; + cl_git_pass(git_blame_file(&g_blame, g_repo, "c.txt", &opts)); + cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame)); + check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "702c7aa5", "c.txt"); +} + +/* * $ git blame -n b.txt -L ,6 * orig line no final line no * commit V author timestamp V diff --git a/tests/resources/blametest.git/objects/1d/81379086fd6d91ee027e883cf6f4703a107dfb b/tests/resources/blametest.git/objects/1d/81379086fd6d91ee027e883cf6f4703a107dfb Binary files differnew file mode 100644 index 000000000..a35dd56ce --- /dev/null +++ b/tests/resources/blametest.git/objects/1d/81379086fd6d91ee027e883cf6f4703a107dfb diff --git a/tests/resources/blametest.git/objects/34/73c3e21e76492d09b80b7c75569edc275dffcf b/tests/resources/blametest.git/objects/34/73c3e21e76492d09b80b7c75569edc275dffcf Binary files differnew file mode 100644 index 000000000..887deff34 --- /dev/null +++ b/tests/resources/blametest.git/objects/34/73c3e21e76492d09b80b7c75569edc275dffcf diff --git a/tests/resources/blametest.git/objects/40/fcae7fb84378fdb037dc6a3ccbb33669c3f26d b/tests/resources/blametest.git/objects/40/fcae7fb84378fdb037dc6a3ccbb33669c3f26d Binary files differnew file mode 100644 index 000000000..27fc76b18 --- /dev/null +++ b/tests/resources/blametest.git/objects/40/fcae7fb84378fdb037dc6a3ccbb33669c3f26d diff --git a/tests/resources/blametest.git/objects/46/ef45f4ae55c1f5dca64b9e1d7ca77c1798069b b/tests/resources/blametest.git/objects/46/ef45f4ae55c1f5dca64b9e1d7ca77c1798069b Binary files differnew file mode 100644 index 000000000..487ac57f1 --- /dev/null +++ b/tests/resources/blametest.git/objects/46/ef45f4ae55c1f5dca64b9e1d7ca77c1798069b diff --git a/tests/resources/blametest.git/objects/4b/0ca755f5bfd69ed6074f268b05bb0542a42c68 b/tests/resources/blametest.git/objects/4b/0ca755f5bfd69ed6074f268b05bb0542a42c68 Binary files differnew file mode 100644 index 000000000..698f5b135 --- /dev/null +++ b/tests/resources/blametest.git/objects/4b/0ca755f5bfd69ed6074f268b05bb0542a42c68 diff --git a/tests/resources/blametest.git/objects/4d/8400b7ce2d15ef5045c2775ed33e82a326786e b/tests/resources/blametest.git/objects/4d/8400b7ce2d15ef5045c2775ed33e82a326786e Binary files differnew file mode 100644 index 000000000..6e754df84 --- /dev/null +++ b/tests/resources/blametest.git/objects/4d/8400b7ce2d15ef5045c2775ed33e82a326786e diff --git a/tests/resources/blametest.git/objects/6b/52ee554131a5e7bacd15553fbd22408c5a8a6f b/tests/resources/blametest.git/objects/6b/52ee554131a5e7bacd15553fbd22408c5a8a6f Binary files differnew file mode 100644 index 000000000..b53aa0484 --- /dev/null +++ b/tests/resources/blametest.git/objects/6b/52ee554131a5e7bacd15553fbd22408c5a8a6f diff --git a/tests/resources/blametest.git/objects/70/2c7aa5250abc42be69ef78ee8fa47a346cb2ce b/tests/resources/blametest.git/objects/70/2c7aa5250abc42be69ef78ee8fa47a346cb2ce Binary files differnew file mode 100644 index 000000000..1f6f2da43 --- /dev/null +++ b/tests/resources/blametest.git/objects/70/2c7aa5250abc42be69ef78ee8fa47a346cb2ce diff --git a/tests/resources/blametest.git/objects/77/c796837eb003c81d2cd8a6577ef4e7edc61222 b/tests/resources/blametest.git/objects/77/c796837eb003c81d2cd8a6577ef4e7edc61222 Binary files differnew file mode 100644 index 000000000..ae5f740c1 --- /dev/null +++ b/tests/resources/blametest.git/objects/77/c796837eb003c81d2cd8a6577ef4e7edc61222 diff --git a/tests/resources/blametest.git/objects/7e/135d94af53b6c5edbae6a77df8a0f09375e823 b/tests/resources/blametest.git/objects/7e/135d94af53b6c5edbae6a77df8a0f09375e823 Binary files differnew file mode 100644 index 000000000..b374ed185 --- /dev/null +++ b/tests/resources/blametest.git/objects/7e/135d94af53b6c5edbae6a77df8a0f09375e823 diff --git a/tests/resources/blametest.git/objects/92/5bddd7a536a66eecb32faa41abd5bc9c192311 b/tests/resources/blametest.git/objects/92/5bddd7a536a66eecb32faa41abd5bc9c192311 Binary files differnew file mode 100644 index 000000000..aba34fa3c --- /dev/null +++ b/tests/resources/blametest.git/objects/92/5bddd7a536a66eecb32faa41abd5bc9c192311 diff --git a/tests/resources/blametest.git/objects/a3/4ead35680be7b9704fc4c6d750d182e228e02b b/tests/resources/blametest.git/objects/a3/4ead35680be7b9704fc4c6d750d182e228e02b Binary files differnew file mode 100644 index 000000000..121934e79 --- /dev/null +++ b/tests/resources/blametest.git/objects/a3/4ead35680be7b9704fc4c6d750d182e228e02b diff --git a/tests/resources/blametest.git/objects/a4/641ad869ffad601aa8347e0770e949bb6d90df b/tests/resources/blametest.git/objects/a4/641ad869ffad601aa8347e0770e949bb6d90df Binary files differnew file mode 100644 index 000000000..e54827c91 --- /dev/null +++ b/tests/resources/blametest.git/objects/a4/641ad869ffad601aa8347e0770e949bb6d90df diff --git a/tests/resources/blametest.git/objects/ba/9089263dce882885ad84513f31495bf9d31132 b/tests/resources/blametest.git/objects/ba/9089263dce882885ad84513f31495bf9d31132 Binary files differnew file mode 100644 index 000000000..4610c2649 --- /dev/null +++ b/tests/resources/blametest.git/objects/ba/9089263dce882885ad84513f31495bf9d31132 diff --git a/tests/resources/blametest.git/objects/c3/8d3c99946b74173f9b037279f07d505195563f b/tests/resources/blametest.git/objects/c3/8d3c99946b74173f9b037279f07d505195563f Binary files differnew file mode 100644 index 000000000..04fd9ccd3 --- /dev/null +++ b/tests/resources/blametest.git/objects/c3/8d3c99946b74173f9b037279f07d505195563f diff --git a/tests/resources/blametest.git/objects/c4/c13c153a611418325c70d6e630fed373546c4d b/tests/resources/blametest.git/objects/c4/c13c153a611418325c70d6e630fed373546c4d Binary files differnew file mode 100644 index 000000000..ba52060e4 --- /dev/null +++ b/tests/resources/blametest.git/objects/c4/c13c153a611418325c70d6e630fed373546c4d diff --git a/tests/resources/blametest.git/objects/d2/bc4f27cbb72260eeec350087d81a60a122efe9 b/tests/resources/blametest.git/objects/d2/bc4f27cbb72260eeec350087d81a60a122efe9 Binary files differnew file mode 100644 index 000000000..b4d6c6d5f --- /dev/null +++ b/tests/resources/blametest.git/objects/d2/bc4f27cbb72260eeec350087d81a60a122efe9 diff --git a/tests/resources/blametest.git/objects/d3/c7316f0075debfe53b25e58f56b0a4b46e18c3 b/tests/resources/blametest.git/objects/d3/c7316f0075debfe53b25e58f56b0a4b46e18c3 new file mode 100644 index 000000000..73f00ee33 --- /dev/null +++ b/tests/resources/blametest.git/objects/d3/c7316f0075debfe53b25e58f56b0a4b46e18c3 @@ -0,0 +1,4 @@ +xmΣHSݚb*Q`c7lwyH)?)RPF1]. @YĕEEK WsKB\@Hg9UP|!/p"!D$a +LeN3Ч ^O9RL[1]P +P`@>sR@EF?oZmͽk߿J
\ΰ0ߜ[$YR4M߫9?{.)ui>$9{s +XwOi&E4<VWr}fJewH}eo
}ȼ1<r'Gބ"';LkDNoխs0݃4+n
XUy%UUalkMrzvuv̐C{n6t?^I2:gNG+zϮ=W=#̩HbNj솇}q(\)pC\r%+e"ng $w3z>MF`eRN9*=O&]t6{aR~piSNÒ :@u*B֍89^r)ܴV + :lM1`|\kKJh HpHzs%Rv94v_MA(E+QfQsgAJ6F/xc+ߟհqiK苬_'ьGUeQy?!k{+0ƒ}7|c^Cż/FקX( 29z\6M`ԣbϏsݙF1Ӑcޢt?y2CIe osI
\ No newline at end of file diff --git a/tests/resources/blametest.git/objects/d6/7268771ef5244f4aa224df29d4e4ae0bed2fd8 b/tests/resources/blametest.git/objects/d6/7268771ef5244f4aa224df29d4e4ae0bed2fd8 Binary files differnew file mode 100644 index 000000000..ee4847819 --- /dev/null +++ b/tests/resources/blametest.git/objects/d6/7268771ef5244f4aa224df29d4e4ae0bed2fd8 diff --git a/tests/resources/blametest.git/objects/d6/afeea2c4657c743dedab24a8a62da96f63547d b/tests/resources/blametest.git/objects/d6/afeea2c4657c743dedab24a8a62da96f63547d Binary files differnew file mode 100644 index 000000000..f3e52be6b --- /dev/null +++ b/tests/resources/blametest.git/objects/d6/afeea2c4657c743dedab24a8a62da96f63547d diff --git a/tests/resources/blametest.git/objects/d9/3e87a0863c7ec5e772f99e72ca9efddf0ca718 b/tests/resources/blametest.git/objects/d9/3e87a0863c7ec5e772f99e72ca9efddf0ca718 Binary files differnew file mode 100644 index 000000000..e1c0f0095 --- /dev/null +++ b/tests/resources/blametest.git/objects/d9/3e87a0863c7ec5e772f99e72ca9efddf0ca718 diff --git a/tests/resources/blametest.git/objects/f0/5190494260c2f6b6d045ac9bf27cb6d7e0abcc b/tests/resources/blametest.git/objects/f0/5190494260c2f6b6d045ac9bf27cb6d7e0abcc Binary files differnew file mode 100644 index 000000000..6df7d3495 --- /dev/null +++ b/tests/resources/blametest.git/objects/f0/5190494260c2f6b6d045ac9bf27cb6d7e0abcc diff --git a/tests/resources/blametest.git/objects/f4/f4b926582a2c23c6e3ba05309eaa89244c1d68 b/tests/resources/blametest.git/objects/f4/f4b926582a2c23c6e3ba05309eaa89244c1d68 Binary files differnew file mode 100644 index 000000000..32c1cdfdd --- /dev/null +++ b/tests/resources/blametest.git/objects/f4/f4b926582a2c23c6e3ba05309eaa89244c1d68 diff --git a/tests/resources/blametest.git/objects/fa/01940156471352d5483b4f26b7c849dfaa7eef b/tests/resources/blametest.git/objects/fa/01940156471352d5483b4f26b7c849dfaa7eef Binary files differnew file mode 100644 index 000000000..b392e4494 --- /dev/null +++ b/tests/resources/blametest.git/objects/fa/01940156471352d5483b4f26b7c849dfaa7eef diff --git a/tests/resources/blametest.git/refs/heads/master b/tests/resources/blametest.git/refs/heads/master index 994877a20..9d1715881 100644 --- a/tests/resources/blametest.git/refs/heads/master +++ b/tests/resources/blametest.git/refs/heads/master @@ -1 +1 @@ -836bc00b06cb60eb0f629e237ad2b58adb2cfc7e +d93e87a0863c7ec5e772f99e72ca9efddf0ca718 |