Skip to content

Commit

Permalink
Fixed consecutive lines with same blame info not appearing in blame.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
devnev authored and Byron committed Jul 18, 2011
1 parent a848569 commit 6e86f8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions git/db/cmd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@ def blame(self, rev, file):
if len(digits) == 3:
info = {'id': firstpart}
blames.append([None, []])
elif info['id'] != firstpart:
info = {'id': firstpart}
blames.append([commits.get(firstpart), []])
# END blame data initialization
else:
m = self.re_author_committer_start.search(firstpart)
Expand Down Expand Up @@ -747,8 +750,8 @@ def blame(self, rev, file):
m = self.re_tab_full_line.search(line)
text, = m.groups()
blames[-1][0] = c
blames[-1][1].append( text )
info = None
blames[-1][1].append(text)
info = { 'id' : sha }
# END if we collected commit info
# END distinguish filename,summary,rest
# END distinguish author|committer vs filename,summary,rest
Expand Down
9 changes: 9 additions & 0 deletions git/test/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ def test_should_display_blame_information(self, git):
assert_true( isinstance( tlist[0], basestring ) )
assert_true( len( tlist ) < sum( len(t) for t in tlist ) ) # test for single-char bug

def test_blame_real(self):
c = 0
for item in self.rorepo.head.commit.tree.traverse(
predicate=lambda i, d: i.type == 'blob' and i.path.endswith('.py')):
c += 1
b = self.rorepo.blame(self.rorepo.head, item.path)
#END for each item to traverse
assert c

def test_untracked_files(self):
base = self.rorepo.working_tree_dir
files = ( join_path_native(base, "__test_myfile"),
Expand Down

0 comments on commit 6e86f8a

Please sign in to comment.