Defect #3832 » 0001-switched-to-git-blame-p.patch
| lib/redmine/scm/adapters/git_adapter.rb | ||
|---|---|---|
|
|
||
|
def annotate(path, identifier=nil)
|
||
|
identifier = 'HEAD' if identifier.blank?
|
||
|
cmd = "#{GIT_BIN} --git-dir #{target('')} blame -l #{shell_quote identifier} -- #{shell_quote path}"
|
||
|
cmd = "#{GIT_BIN} --git-dir #{target('')} blame -p #{shell_quote identifier} -- #{shell_quote path}"
|
||
|
blame = Annotate.new
|
||
|
content = nil
|
||
|
shellout(cmd) { |io| io.binmode; content = io.read }
|
||
|
return nil if $? && $?.exitstatus != 0
|
||
|
# git annotates binary files
|
||
|
return nil if content.is_binary_data?
|
||
|
ident = ""
|
||
|
src = ""
|
||
|
auth = Hash.new
|
||
|
content.split("\n").each do |line|
|
||
|
next unless line =~ /([0-9a-f]{39,40})\s\((\w*)[^\)]*\)(.*)/
|
||
|
blame.add_line($3.rstrip, Revision.new(:identifier => $1, :author => $2.strip))
|
||
|
if line =~ /^([0-9a-f]{39,40})\s.*/
|
||
|
ident = $1
|
||
|
end
|
||
|
if line =~ /^author (.*)/
|
||
|
auth[ident] = $1.strip
|
||
|
end
|
||
|
if line =~ /^\t(.*)/
|
||
|
src = $1
|
||
|
blame.add_line(src, Revision.new(:identifier => ident, :author => auth[ident]))
|
||
|
end
|
||
|
end
|
||
|
blame.add_line("", Revision.new(:identifier => ident, :author => auth[ident])) if blame.empty?
|
||
|
blame
|
||
|
end
|
||
|
|
||