blame: add option to ignore whitespace changes

This commit is contained in:
Carl Schwan
2020-01-29 02:00:04 +01:00
parent 918a7d1955
commit 9830ab3d25
28 changed files with 31 additions and 4 deletions

View File

@@ -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;
/**

View File

@@ -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 */

View File

@@ -238,6 +238,24 @@ void test_blame_simple__can_restrict_lines_min(void)
check_blame_hunk_index(g_repo, g_blame, 1, 11, 5, 0, "aa06ecca", "b.txt");
}
/*
* $ 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

View File

@@ -0,0 +1,4 @@
xm“ÉΣH„çÌSÔÝš†b©*¤îQ³Û`³c7öÅl ¿—§w<>æÖyH)?)R©PF1].Ý ƒ…¿–¹ª@ž‰ YÄ•EEKˆ<4B>•„ Ws<57>…¼KBŽ¥®Ù\<5C> @Hàêšg9ÈU¹P| ª!/p"Ì!ÉD$Š„a
LeëÒN3Ч ÈÙ ø^OÓÏ9ËéRLóõ[1]þP +ˆP€`Ã@†¡>ôsàRÍ@ÉæEûÈFð½ø ?µûoð­Zÿ m®Í½kÀß¿JÖŒ<C396>Áΰ¥0òµßœè¼Ý[$Y¤Rï4Mß«Ë9?ò¶{·–·äÙ.µÅ)æuià>$¥9{ÿs
¤X€w‰¦Oçi®&EÔ4<ÏVWr}fJ¥ewHÖÄ}«ü™eo¦ÖÖ £}ȼ1<ñrï'<27>ÆÝG§‹Þ„·Ä"î';LëkÞDN<44>­¢sÙ0Ú݃4+ºnŸò¸¯ XõUÒyð%èUUùaïŸlkñò°¬§MrzûvìÙuvÌ<>CØ{”âñn6t¨?ýÙ^I2:ÉgNG+§z©Ï®µš=WÌ=#Ì©<C38C>ßÅæHbNj솇}Æøq( ƒ˜»Ž¯\)p×½ƒ·Cóôã<C3B4>\rÝ%+<2B><EFBFBD>¡¹±e÷"Ùn§g $w¤3z¢>M•ˆ˜F`Òe¤R€N¢Îƒú»9´Èæ·*=O&]­t6È{Îa²žõR~Ìñ°ËpiSÊNà Ý:ø@úu*ëBÏÖ<C38F>¸ÛùÊ8²¸9^Ïr„)Ü´V
ÈÉü†¯Ý÷ ×:»lÛãM1`ˆØÏ|\k¸Kõ£©JÍh ¤ÜHpÖHzs%åRçûˆ÷v94Øóv_MAª(½E+QÑöf¥QsgA­÷Jî»6ÆFÎú/—xcòÒ+ߟհ«qœiäËáK謊_Æç'ÕÄÑŒG»UeÍQÀºÅy?!îkëØ{+0Æ}7|cí^Cíż·£/F×§XÖ( 29zÂ\6‡M`Ô£b¹Ï<C2B9>sÝ™F<1B>ÆÓ<C386>cÞ¢ñËãt÷ƒ?y<>¨ÿ2£ÙêŸCIe òoËs¡þæÌIª

View File

@@ -1 +1 @@
836bc00b06cb60eb0f629e237ad2b58adb2cfc7e
d93e87a0863c7ec5e772f99e72ca9efddf0ca718