summaryrefslogtreecommitdiff
path: root/t/t8013-blame-ignore-revs.sh
diff options
context:
space:
mode:
authorBarret Rhoden <brho@google.com>2019-05-15 21:45:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-05-16 02:36:23 (GMT)
commit8934ac8c92a1dc805f7bbd86cbc251ade66e1161 (patch)
tree47df762fd15df5c043f9adf498984a167c306765 /t/t8013-blame-ignore-revs.sh
parentae3f36dea16e51041c56ba9ed6b38380c8421816 (diff)
downloadgit-8934ac8c92a1dc805f7bbd86cbc251ade66e1161.zip
git-8934ac8c92a1dc805f7bbd86cbc251ade66e1161.tar.gz
git-8934ac8c92a1dc805f7bbd86cbc251ade66e1161.tar.bz2
blame: add config options for the output of ignored or unblamable lines
When ignoring commits, the commit that is blamed might not be responsible for the change, due to the inaccuracy of our heuristic. Users might want to know when a particular line has a potentially inaccurate blame. Furthermore, guess_line_blames() may fail to find any parent commit for a given line touched by an ignored commit. Those 'unblamable' lines remain blamed on an ignored commit. Users might want to know if a line is unblamable so that they do not spend time investigating a commit they know is uninteresting. This patch adds two config options to mark these two types of lines in the output of blame. The first option can identify ignored lines by specifying blame.markIgnoredLines. When this option is set, each blame line that was blamed on a commit other than the ignored commit is marked with a '?'. For example: 278b6158d6fdb (Barret Rhoden 2016-04-11 13:57:54 -0400 26) appears as: ?278b6158d6fd (Barret Rhoden 2016-04-11 13:57:54 -0400 26) where the '?' is placed before the commit, and the hash has one fewer characters. Sometimes we are unable to even guess at what ancestor commit touched a line. These lines are 'unblamable.' The second option, blame.markUnblamableLines, will mark the line with '*'. For example, say we ignore e5e8d36d04cbe, yet we are unable to blame this line on another commit: e5e8d36d04cbe (Barret Rhoden 2016-04-11 13:57:54 -0400 26) appears as: *e5e8d36d04cb (Barret Rhoden 2016-04-11 13:57:54 -0400 26) When these config options are used together, every line touched by an ignored commit will be marked with either a '?' or a '*'. Signed-off-by: Barret Rhoden <brho@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t8013-blame-ignore-revs.sh')
-rwxr-xr-xt/t8013-blame-ignore-revs.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh
index fdb2fa8..36dc31e 100755
--- a/t/t8013-blame-ignore-revs.sh
+++ b/t/t8013-blame-ignore-revs.sh
@@ -121,6 +121,77 @@ test_expect_success bad_files_and_revs '
test_must_fail git blame file --ignore-revs-file ignore_norev 2>err &&
test_i18ngrep "invalid object name: NOREV" err
'
+
+# For ignored revs that have added 'unblamable' lines, mark those lines with a
+# '*'
+# A--B--X--Y
+# Lines 3 and 4 are from Y and unblamable. This was set up in
+# ignore_rev_adding_unblamable_lines.
+test_expect_success mark_unblamable_lines '
+ git config --add blame.markUnblamableLines true &&
+
+ git blame --ignore-rev Y file >blame_raw &&
+ echo "*" >expect &&
+
+ sed -n "3p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual &&
+
+ sed -n "4p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual
+ '
+
+# Commit Z will touch the first two lines. Y touched all four.
+# A--B--X--Y--Z
+# The blame output when ignoring Z should be:
+# ?Y ... 1)
+# ?Y ... 2)
+# Y ... 3)
+# Y ... 4)
+# We're checking only the first character
+test_expect_success mark_ignored_lines '
+ git config --add blame.markIgnoredLines true &&
+
+ test_write_lines line-one-Z line-two-Z y3 y4 >file &&
+ git add file &&
+ test_tick &&
+ git commit -m Z &&
+ git tag Z &&
+
+ git blame --ignore-rev Z file >blame_raw &&
+ echo "?" >expect &&
+
+ sed -n "1p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual &&
+
+ sed -n "2p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual &&
+
+ sed -n "3p" blame_raw | cut -c1 >actual &&
+ ! test_cmp expect actual &&
+
+ sed -n "4p" blame_raw | cut -c1 >actual &&
+ ! test_cmp expect actual
+ '
+
+# For ignored revs that added 'unblamable' lines and more recent commits changed
+# the blamable lines, mark the unblamable lines with a
+# '*'
+# A--B--X--Y--Z
+# Lines 3 and 4 are from Y and unblamable, as set up in
+# ignore_rev_adding_unblamable_lines. Z changed lines 1 and 2.
+test_expect_success mark_unblamable_lines_intermediate '
+ git config --add blame.markUnblamableLines true &&
+
+ git blame --ignore-rev Y file >blame_raw 2>stderr &&
+ echo "*" >expect &&
+
+ sed -n "3p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual &&
+
+ sed -n "4p" blame_raw | cut -c1 >actual &&
+ test_cmp expect actual
+ '
+
# The heuristic called by guess_line_blames() tries to find the size of a
# blame_entry 'e' in the parent's address space. Those calculations need to
# check for negative or zero values for when a blame entry is completely outside