diff options
author | Ungureanu Marius <marius.ungureanu@xamarin.com> | 2015-05-30 20:10:00 +0300 |
---|---|---|
committer | Ungureanu Marius <marius.ungureanu@xamarin.com> | 2015-05-30 20:31:52 +0300 |
commit | a1c35c733fdb845d80748622e45b588990a4c2b0 (patch) | |
tree | 7bb7acbd7d28199cfb12d8e252c9e3b59d108c5e | |
parent | 0ff096cbd8b3b8d1c82baa57b4aab7decb19b100 (diff) |
Introduce git_blame_options GIT_BLAME_DONT_FOLLOW_RENAMES flag
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | include/git2/blame.h | 2 | ||||
-rw-r--r-- | src/blame_git.c | 12 | ||||
-rw-r--r-- | tests/blame/simple.c | 16 |
4 files changed, 28 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2691ba5a3..2a44ee6e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -132,6 +132,9 @@ support for HTTPS connections insead of OpenSSL. * `git_blame_options` flags can now be configured to not use similarity heuristics during a blame via GIT_BLAME_FOLLOW_EXACT_RENAMES flag. +* `git_blame_options` flags can now be configured to not follow renames + at all during a blame via GIT_BLAME_DONT_FOLLOW_RENAMES flag. + ### API removals * `git_remote_save()` and `git_remote_clear_refspecs()` have been diff --git a/include/git2/blame.h b/include/git2/blame.h index ccd70d92d..bec0e9776 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -45,6 +45,8 @@ typedef enum { GIT_BLAME_FIRST_PARENT = (1<<4), /** Take less time to generate blame by only following exact matches */ GIT_BLAME_FOLLOW_EXACT_RENAMES = (1<<5), + /** Take less time to generate blame by not checking for renames */ + GIT_BLAME_DONT_FOLLOW_RENAMES = (1<<6), } git_blame_flag_t; /** diff --git a/src/blame_git.c b/src/blame_git.c index 8a6a752f7..4473278c9 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -436,12 +436,14 @@ static git_blame__origin* find_origin( if (0 != git_diff_tree_to_tree(&difflist, blame->repository, ptree, otree, &diffopts)) goto cleanup; - /* Let diff find renames based on blame options */ - findopts.flags = blame->options.flags & GIT_BLAME_FOLLOW_EXACT_RENAMES ? - GIT_DIFF_FIND_EXACT_MATCH_ONLY : GIT_DIFF_FIND_RENAMES; + if (!(blame->options.flags & GIT_BLAME_DONT_FOLLOW_RENAMES)) { + /* Let diff find renames based on blame options */ + findopts.flags = blame->options.flags & GIT_BLAME_FOLLOW_EXACT_RENAMES ? + GIT_DIFF_FIND_EXACT_MATCH_ONLY : GIT_DIFF_FIND_RENAMES; - if (0 != git_diff_find_similar(difflist, &findopts)) - goto cleanup; + if (0 != git_diff_find_similar(difflist, &findopts)) + goto cleanup; + } /* Find one that matches */ for (i=0; i<(int)git_diff_num_deltas(difflist); i++) { diff --git a/tests/blame/simple.c b/tests/blame/simple.c index 542545095..f820242d5 100644 --- a/tests/blame/simple.c +++ b/tests/blame/simple.c @@ -355,3 +355,19 @@ void test_blame_simple__can_follow_only_exact_renames(void) cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame)); check_blame_hunk_index(g_repo, g_blame, 0, 1, 10, 0, "fa2ae14c", "d_similar.txt"); } + +void test_blame_simple__does_not_follow_renames(void) +{ + git_blame_options opts = GIT_BLAME_OPTIONS_INIT; + opts.flags |= GIT_BLAME_DONT_FOLLOW_RENAMES; + + cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git"))); + + cl_git_pass(git_blame_file(&g_blame, g_repo, "c_exact.txt", &opts)); + cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame)); + check_blame_hunk_index(g_repo, g_blame, 0, 1, 10, 0, "dc0ba436", "c_exact.txt"); + + cl_git_pass(git_blame_file(&g_blame, g_repo, "d_similar.txt", &opts)); + cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame)); + check_blame_hunk_index(g_repo, g_blame, 0, 1, 10, 0, "fa2ae14c", "d_similar.txt"); +} |