Skip to content

Commit 6e86f8a

Browse files
devnevByron
authored andcommitted
Fixed consecutive lines with same blame info not appearing in blame.
This fixes a bug when parsing blame -p output: Full commit info headers only appear for the first line from a particular commit, but other lines were ignored as the blame info dict was reset after each line. This patch handles both multiple consecutive lines from a commit and interleaved lines from multiple commits. Added real test to verify blame works against the actual commit, not only a mock of what was produced by blame in old git releases
1 parent a848569 commit 6e86f8a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎git/db/cmd/base.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ def blame(self, rev, file):
701701
iflen(digits) ==3:
702702
info={'id': firstpart}
703703
blames.append([None, []])
704+
elifinfo['id'] !=firstpart:
705+
info={'id': firstpart}
706+
blames.append([commits.get(firstpart), []])
704707
# END blame data initialization
705708
else:
706709
m=self.re_author_committer_start.search(firstpart)
@@ -747,8 +750,8 @@ def blame(self, rev, file):
747750
m=self.re_tab_full_line.search(line)
748751
text, =m.groups()
749752
blames[-1][0] =c
750-
blames[-1][1].append(text)
751-
info=None
753+
blames[-1][1].append(text)
754+
info={'id' : sha }
752755
# END if we collected commit info
753756
# END distinguish filename,summary,rest
754757
# END distinguish author|committer vs filename,summary,rest

‎git/test/db/base.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ def test_should_display_blame_information(self, git):
283283
assert_true( isinstance( tlist[0], basestring ) )
284284
assert_true( len( tlist ) <sum( len(t) fortintlist ) ) # test for single-char bug
285285

286+
deftest_blame_real(self):
287+
c=0
288+
foriteminself.rorepo.head.commit.tree.traverse(
289+
predicate=lambdai, d: i.type=='blob'andi.path.endswith('.py')):
290+
c+=1
291+
b=self.rorepo.blame(self.rorepo.head, item.path)
292+
#END for each item to traverse
293+
assertc
294+
286295
deftest_untracked_files(self):
287296
base=self.rorepo.working_tree_dir
288297
files= ( join_path_native(base, "__test_myfile"),

0 commit comments

Comments
(0)