Unverified Commit 66137ff6 by Patrick Steinhardt Committed by GitHub

Merge pull request #5383 from ognarb/feature/blame-ignore-whitespace

Feature: Allow blame to ignore whitespace change
parents 918a7d19 9830ab3d
......@@ -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;
/**
......
......@@ -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 */
......
......@@ -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
......
836bc00b06cb60eb0f629e237ad2b58adb2cfc7e
d93e87a0863c7ec5e772f99e72ca9efddf0ca718
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment