Skip to content

Commit 4683e57

Browse files
committed
Fixed bug with parsing of -p --incremental git-blame output (for line #'s/change group length)
1 parent 6a572c8 commit 4683e57

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/git/blame.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,24 @@ def construct_blame(file = '', opts = {})
100100
commit = new_commit[0]
101101

102102
line_num = line.sub(/^[a-f0-9]{40} [0-9]+ /, '')
103-
line_num = line_num.sub(/\s[0-9]+.*$/, '') if line_num.match(/\s/)
103+
104+
if line_num.match(/\s[0-9]+/)
105+
block_length = line_num.sub(/^[0-9]+\s/, '').sub(/\s.*$/, '')
106+
107+
line_num = line_num.sub(/\s[0-9]+.*$/, '')
108+
else
109+
block_length = 1
110+
end
104111

105112
# this looks odd, but it's correct... we're initializing this commit's hash, which
106113
# should contain a :hash -> <sha hash> element, among other things, and the hash
107114
# OF commit hashes is indexed on the sha hash, so... yeah :)
108115
#
109116
commits[commit] = {:commit => commit} if ! commits[commit]
110117

111-
parsed_lines[line_num] = commit
118+
for i in line_num.to_i..(line_num.to_i + block_length.to_i - 1)
119+
parsed_lines[i] = commit
120+
end
112121
end
113122

114123
if /^author\s/.match(line)
@@ -134,8 +143,8 @@ def construct_blame(file = '', opts = {})
134143

135144
parsed_lines.each do |line, commit|
136145
commits[commit][:line] = line
137-
138-
@lines[line.to_i] = BlameLine.new(line.to_i, commits[commit])
146+
puts 'line ' + line.to_s + ' added to @lines of Blame'
147+
@lines[line] = BlameLine.new(line, commits[commit])
139148
end
140149
end
141150

0 commit comments

Comments
 (0)