Skip to content

Commit 93121df

Browse files
committed
Merge branch 'jk/blame-coalesce-fix'
When given more than one target line ranges, "git blame -La,b -Lc,d" was over-eager to coalesce groups of original lines and showed incorrect results, which has been corrected. * jk/blame-coalesce-fix: blame: only coalesce lines that are adjacent in result t8003: factor setup out of coalesce test t8003: check output of coalesced blame
2 parents 4499a42 + c2ebaa2 commit 93121df

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

blame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,7 @@ void blame_coalesce(struct blame_scoreboard *sb)
11841184
for (ent = sb->ent; ent && (next = ent->next); ent = next) {
11851185
if (ent->suspect == next->suspect &&
11861186
ent->s_lno + ent->num_lines == next->s_lno &&
1187+
ent->lno + ent->num_lines == next->lno &&
11871188
ent->ignored == next->ignored &&
11881189
ent->unblamable == next->unblamable) {
11891190
ent->num_lines += next->num_lines;

t/t8003-blame-corner-cases.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,14 @@ test_expect_success 'blame file with CRLF core.autocrlf=true' '
273273
grep "A U Thor" actual
274274
'
275275

276-
# Tests the splitting and merging of blame entries in blame_coalesce().
277-
# The output of blame is the same, regardless of whether blame_coalesce() runs
278-
# or not, so we'd likely only notice a problem if blame crashes or assigned
279-
# blame to the "splitting" commit ('SPLIT' below).
280-
test_expect_success 'blame coalesce' '
276+
test_expect_success 'setup coalesce tests' '
281277
cat >giraffe <<-\EOF &&
282278
ABC
283279
DEF
284280
EOF
285281
git add giraffe &&
286282
git commit -m "original file" &&
287-
oid=$(git rev-parse HEAD) &&
283+
orig=$(git rev-parse HEAD) &&
288284
289285
cat >giraffe <<-\EOF &&
290286
ABC
@@ -293,19 +289,33 @@ test_expect_success 'blame coalesce' '
293289
EOF
294290
git add giraffe &&
295291
git commit -m "interior SPLIT line" &&
292+
split=$(git rev-parse HEAD) &&
296293
297294
cat >giraffe <<-\EOF &&
298295
ABC
299296
DEF
300297
EOF
301298
git add giraffe &&
302299
git commit -m "same contents as original" &&
300+
final=$(git rev-parse HEAD)
301+
'
302+
303+
test_expect_success 'blame coalesce' '
304+
cat >expect <<-EOF &&
305+
$orig 1 1 2
306+
$orig 2 2
307+
EOF
308+
git blame --porcelain $final giraffe >actual.raw &&
309+
grep "^$orig" actual.raw >actual &&
310+
test_cmp expect actual
311+
'
303312

313+
test_expect_success 'blame does not coalesce non-adjacent result lines' '
304314
cat >expect <<-EOF &&
305-
$oid 1) ABC
306-
$oid 2) DEF
315+
$orig 1) ABC
316+
$orig 3) DEF
307317
EOF
308-
git -c core.abbrev=$(test_oid hexsz) blame -s giraffe >actual &&
318+
git blame --no-abbrev -s -L1,1 -L3,3 $split giraffe >actual &&
309319
test_cmp expect actual
310320
'
311321

0 commit comments

Comments
 (0)