2011-05-06 15:45:20 +04:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2008-03-12 23:28:49 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-06 15:45:20 +04:00
|
|
|
#
|
2008-03-12 23:28:49 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-06 15:45:20 +04:00
|
|
|
#
|
2008-03-12 23:28:49 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
require 'redmine/scm/adapters/abstract_adapter'
|
|
|
|
|
|
|
|
module Redmine
|
|
|
|
module Scm
|
2011-02-14 09:14:34 +03:00
|
|
|
module Adapters
|
2008-03-12 23:28:49 +03:00
|
|
|
class GitAdapter < AbstractAdapter
|
2011-02-24 16:01:13 +03:00
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
# Git executable name
|
2011-02-04 13:24:10 +03:00
|
|
|
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
|
2008-03-12 23:28:49 +03:00
|
|
|
|
2012-02-12 10:22:59 +04:00
|
|
|
class GitBranch < Branch
|
|
|
|
attr_accessor :is_default
|
|
|
|
end
|
|
|
|
|
2011-02-14 09:14:34 +03:00
|
|
|
class << self
|
|
|
|
def client_command
|
|
|
|
@@bin ||= GIT_BIN
|
|
|
|
end
|
|
|
|
|
|
|
|
def sq_bin
|
2011-07-15 20:31:51 +04:00
|
|
|
@@sq_bin ||= shell_quote_command
|
2011-02-14 09:14:34 +03:00
|
|
|
end
|
|
|
|
|
2011-02-15 08:58:31 +03:00
|
|
|
def client_version
|
|
|
|
@@client_version ||= (scm_command_version || [])
|
|
|
|
end
|
|
|
|
|
2011-02-14 09:14:34 +03:00
|
|
|
def client_available
|
|
|
|
!client_version.empty?
|
2011-02-15 08:58:31 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def scm_command_version
|
2011-03-03 08:32:33 +03:00
|
|
|
scm_version = scm_version_from_command_line.dup
|
2011-02-22 11:05:51 +03:00
|
|
|
if scm_version.respond_to?(:force_encoding)
|
|
|
|
scm_version.force_encoding('ASCII-8BIT')
|
|
|
|
end
|
2011-02-15 08:58:31 +03:00
|
|
|
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
|
|
|
|
m[2].scan(%r{\d+}).collect(&:to_i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def scm_version_from_command_line
|
2011-02-20 04:33:09 +03:00
|
|
|
shellout("#{sq_bin} --version --no-color") { |io| io.read }.to_s
|
2011-02-14 09:14:34 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-24 16:01:13 +03:00
|
|
|
def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
|
|
|
|
super
|
2011-05-04 09:01:28 +04:00
|
|
|
@path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
|
2011-05-21 06:39:42 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def path_encoding
|
|
|
|
@path_encoding
|
2011-02-24 16:01:13 +03:00
|
|
|
end
|
|
|
|
|
2009-08-16 02:41:40 +04:00
|
|
|
def info
|
|
|
|
begin
|
|
|
|
Info.new(:root_url => url, :lastrev => lastrev('',nil))
|
|
|
|
rescue
|
|
|
|
nil
|
2008-05-29 22:48:00 +04:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
|
2009-08-16 02:41:40 +04:00
|
|
|
def branches
|
2010-02-20 16:35:22 +03:00
|
|
|
return @branches if @branches
|
|
|
|
@branches = []
|
2011-10-28 09:17:46 +04:00
|
|
|
cmd_args = %w|branch --no-color --verbose --no-abbrev|
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) do |io|
|
2008-03-12 23:28:49 +03:00
|
|
|
io.each_line do |line|
|
2012-02-12 10:22:59 +04:00
|
|
|
branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
|
|
|
|
bran = GitBranch.new(branch_rev[2])
|
|
|
|
bran.revision = branch_rev[3]
|
|
|
|
bran.scmid = branch_rev[3]
|
|
|
|
bran.is_default = ( branch_rev[1] == '*' )
|
2011-10-28 09:17:46 +04:00
|
|
|
@branches << bran
|
2009-08-16 02:41:40 +04:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2010-02-20 16:35:22 +03:00
|
|
|
@branches.sort!
|
2011-03-08 08:18:04 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
|
|
|
|
2009-08-16 02:41:40 +04:00
|
|
|
def tags
|
2010-02-20 16:35:22 +03:00
|
|
|
return @tags if @tags
|
2011-03-08 09:10:53 +03:00
|
|
|
cmd_args = %w|tag|
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) do |io|
|
2010-02-20 16:35:22 +03:00
|
|
|
@tags = io.readlines.sort!.map{|t| t.strip}
|
2008-03-13 02:09:11 +03:00
|
|
|
end
|
2011-03-08 09:10:53 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2009-08-16 02:41:40 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_branch
|
2011-03-15 10:14:19 +03:00
|
|
|
bras = self.branches
|
2011-03-19 18:50:08 +03:00
|
|
|
return nil if bras.nil?
|
2012-02-12 10:22:59 +04:00
|
|
|
default_bras = bras.select{|x| x.is_default == true}
|
2012-02-12 12:26:31 +04:00
|
|
|
return default_bras.first.to_s if ! default_bras.empty?
|
|
|
|
master_bras = bras.select{|x| x.to_s == 'master'}
|
|
|
|
master_bras.empty? ? bras.first.to_s : 'master'
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-02-20 04:33:30 +03:00
|
|
|
|
2011-05-04 22:07:50 +04:00
|
|
|
def entry(path=nil, identifier=nil)
|
|
|
|
parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
|
|
|
|
search_path = parts[0..-2].join('/')
|
|
|
|
search_name = parts[-1]
|
|
|
|
if search_path.blank? && search_name.blank?
|
|
|
|
# Root entry
|
|
|
|
Entry.new(:path => '', :kind => 'dir')
|
|
|
|
else
|
|
|
|
# Search for the entry in the parent directory
|
2011-05-05 15:43:29 +04:00
|
|
|
es = entries(search_path, identifier,
|
|
|
|
options = {:report_last_commit => false})
|
2011-05-04 22:07:50 +04:00
|
|
|
es ? es.detect {|e| e.name == search_name} : nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-04 18:11:25 +04:00
|
|
|
def entries(path=nil, identifier=nil, options={})
|
2008-03-12 23:28:49 +03:00
|
|
|
path ||= ''
|
2011-03-08 07:50:48 +03:00
|
|
|
p = scm_iconv(@path_encoding, 'UTF-8', path)
|
2008-03-12 23:28:49 +03:00
|
|
|
entries = Entries.new
|
2011-03-08 07:50:48 +03:00
|
|
|
cmd_args = %w|ls-tree -l|
|
|
|
|
cmd_args << "HEAD:#{p}" if identifier.nil?
|
|
|
|
cmd_args << "#{identifier}:#{p}" if identifier
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) do |io|
|
2008-03-12 23:28:49 +03:00
|
|
|
io.each_line do |line|
|
|
|
|
e = line.chomp.to_s
|
2010-09-27 01:54:52 +04:00
|
|
|
if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\t(.+)$/
|
2008-03-12 23:28:49 +03:00
|
|
|
type = $1
|
2011-03-08 07:50:48 +03:00
|
|
|
sha = $2
|
2008-03-12 23:28:49 +03:00
|
|
|
size = $3
|
|
|
|
name = $4
|
2011-03-08 16:22:53 +03:00
|
|
|
if name.respond_to?(:force_encoding)
|
|
|
|
name.force_encoding(@path_encoding)
|
|
|
|
end
|
2011-03-08 14:13:18 +03:00
|
|
|
full_path = p.empty? ? name : "#{p}/#{name}"
|
2011-03-08 07:50:48 +03:00
|
|
|
n = scm_iconv('UTF-8', @path_encoding, name)
|
|
|
|
full_p = scm_iconv('UTF-8', @path_encoding, full_path)
|
|
|
|
entries << Entry.new({:name => n,
|
|
|
|
:path => full_p,
|
2009-08-16 02:41:40 +04:00
|
|
|
:kind => (type == "tree") ? 'dir' : 'file',
|
|
|
|
:size => (type == "tree") ? nil : size,
|
2011-05-04 22:08:30 +04:00
|
|
|
:lastrev => options[:report_last_commit] ?
|
|
|
|
lastrev(full_path, identifier) : Revision.new
|
2009-08-16 02:41:40 +04:00
|
|
|
}) unless entries.detect{|entry| entry.name == name}
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
entries.sort_by_name
|
2011-03-08 07:50:48 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2011-02-28 17:12:24 +03:00
|
|
|
def lastrev(path, rev)
|
2009-08-16 02:41:40 +04:00
|
|
|
return nil if path.nil?
|
2011-04-06 11:16:25 +04:00
|
|
|
cmd_args = %w|log --no-color --encoding=UTF-8 --date=iso --pretty=fuller --no-merges -n 1|
|
2011-04-24 13:55:26 +04:00
|
|
|
cmd_args << rev if rev
|
2011-02-28 17:12:24 +03:00
|
|
|
cmd_args << "--" << path unless path.empty?
|
2011-01-03 13:45:00 +03:00
|
|
|
lines = []
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) { |io| lines = io.readlines }
|
2011-01-03 13:45:00 +03:00
|
|
|
begin
|
|
|
|
id = lines[0].split[1]
|
|
|
|
author = lines[1].match('Author:\s+(.*)$')[1]
|
2011-02-14 11:45:54 +03:00
|
|
|
time = Time.parse(lines[4].match('CommitDate:\s+(.*)$')[1])
|
2009-08-16 02:41:40 +04:00
|
|
|
|
|
|
|
Revision.new({
|
|
|
|
:identifier => id,
|
2011-04-24 13:55:26 +04:00
|
|
|
:scmid => id,
|
|
|
|
:author => author,
|
|
|
|
:time => time,
|
|
|
|
:message => nil,
|
|
|
|
:paths => nil
|
2011-02-28 17:12:24 +03:00
|
|
|
})
|
2011-01-03 13:45:00 +03:00
|
|
|
rescue NoMethodError => e
|
2009-08-16 02:41:40 +04:00
|
|
|
logger.error("The revision '#{path}' has a wrong format")
|
|
|
|
return nil
|
|
|
|
end
|
2011-02-28 17:12:24 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2009-08-16 02:41:40 +04:00
|
|
|
end
|
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def revisions(path, identifier_from, identifier_to, options={})
|
2011-05-06 17:49:33 +04:00
|
|
|
revs = Revisions.new
|
2012-03-28 19:40:37 +04:00
|
|
|
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin|
|
2011-02-20 04:33:50 +03:00
|
|
|
cmd_args << "--reverse" if options[:reverse]
|
|
|
|
cmd_args << "-n" << "#{options[:limit].to_i}" if options[:limit]
|
2012-03-28 19:40:37 +04:00
|
|
|
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
|
|
|
|
revisions = []
|
2012-02-09 03:38:35 +04:00
|
|
|
if identifier_from || identifier_to
|
2012-03-28 19:40:37 +04:00
|
|
|
revisions << ""
|
|
|
|
revisions[0] << "#{identifier_from}.." if identifier_from
|
|
|
|
revisions[0] << "#{identifier_to}" if identifier_to
|
2012-02-09 03:38:35 +04:00
|
|
|
else
|
2012-03-28 19:40:37 +04:00
|
|
|
unless options[:includes].blank?
|
|
|
|
revisions += options[:includes]
|
|
|
|
end
|
2012-02-09 03:38:35 +04:00
|
|
|
unless options[:excludes].blank?
|
2012-03-28 19:40:37 +04:00
|
|
|
revisions += options[:excludes].map{|r| "^#{r}"}
|
2012-02-09 03:38:35 +04:00
|
|
|
end
|
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2012-03-28 19:40:37 +04:00
|
|
|
git_cmd(cmd_args, {:write_stdin => true}) do |io|
|
|
|
|
io.binmode
|
|
|
|
io.puts(revisions.join("\n"))
|
|
|
|
io.close_write
|
2008-03-12 23:28:49 +03:00
|
|
|
files=[]
|
|
|
|
changeset = {}
|
|
|
|
parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
|
|
|
|
|
|
|
|
io.each_line do |line|
|
2011-10-28 08:58:26 +04:00
|
|
|
if line =~ /^commit ([0-9a-f]{40})(( [0-9a-f]{40})*)$/
|
2008-03-12 23:28:49 +03:00
|
|
|
key = "commit"
|
|
|
|
value = $1
|
2011-10-28 08:58:26 +04:00
|
|
|
parents_str = $2
|
2008-03-12 23:28:49 +03:00
|
|
|
if (parsing_descr == 1 || parsing_descr == 2)
|
|
|
|
parsing_descr = 0
|
2009-08-16 02:41:40 +04:00
|
|
|
revision = Revision.new({
|
|
|
|
:identifier => changeset[:commit],
|
2011-04-24 13:55:26 +04:00
|
|
|
:scmid => changeset[:commit],
|
|
|
|
:author => changeset[:author],
|
|
|
|
:time => Time.parse(changeset[:date]),
|
|
|
|
:message => changeset[:description],
|
2011-10-28 08:58:26 +04:00
|
|
|
:paths => files,
|
|
|
|
:parents => changeset[:parents]
|
2009-08-16 02:41:40 +04:00
|
|
|
})
|
2011-05-13 10:03:26 +04:00
|
|
|
if block_given?
|
|
|
|
yield revision
|
|
|
|
else
|
|
|
|
revs << revision
|
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
changeset = {}
|
|
|
|
files = []
|
|
|
|
end
|
|
|
|
changeset[:commit] = $1
|
2011-10-28 08:58:26 +04:00
|
|
|
unless parents_str.nil? or parents_str == ""
|
|
|
|
changeset[:parents] = parents_str.strip.split(' ')
|
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
elsif (parsing_descr == 0) && line =~ /^(\w+):\s*(.*)$/
|
|
|
|
key = $1
|
|
|
|
value = $2
|
|
|
|
if key == "Author"
|
|
|
|
changeset[:author] = value
|
2008-11-09 15:07:35 +03:00
|
|
|
elsif key == "CommitDate"
|
2008-03-12 23:28:49 +03:00
|
|
|
changeset[:date] = value
|
|
|
|
end
|
|
|
|
elsif (parsing_descr == 0) && line.chomp.to_s == ""
|
|
|
|
parsing_descr = 1
|
|
|
|
changeset[:description] = ""
|
2009-08-16 02:41:40 +04:00
|
|
|
elsif (parsing_descr == 1 || parsing_descr == 2) \
|
2011-03-08 06:29:11 +03:00
|
|
|
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
|
2008-03-12 23:28:49 +03:00
|
|
|
parsing_descr = 2
|
2011-03-08 06:29:11 +03:00
|
|
|
fileaction = $1
|
|
|
|
filepath = $2
|
2011-03-08 06:29:58 +03:00
|
|
|
p = scm_iconv('UTF-8', @path_encoding, filepath)
|
|
|
|
files << {:action => fileaction, :path => p}
|
2009-08-16 02:41:40 +04:00
|
|
|
elsif (parsing_descr == 1 || parsing_descr == 2) \
|
2011-03-08 06:29:11 +03:00
|
|
|
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
|
2009-08-16 02:41:40 +04:00
|
|
|
parsing_descr = 2
|
2011-03-08 06:29:11 +03:00
|
|
|
fileaction = $1
|
|
|
|
filepath = $3
|
2011-03-08 06:29:58 +03:00
|
|
|
p = scm_iconv('UTF-8', @path_encoding, filepath)
|
|
|
|
files << {:action => fileaction, :path => p}
|
2008-03-12 23:28:49 +03:00
|
|
|
elsif (parsing_descr == 1) && line.chomp.to_s == ""
|
|
|
|
parsing_descr = 2
|
|
|
|
elsif (parsing_descr == 1)
|
|
|
|
changeset[:description] << line[4..-1]
|
|
|
|
end
|
2011-03-08 07:50:28 +03:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
|
2008-06-29 13:41:42 +04:00
|
|
|
if changeset[:commit]
|
2009-08-16 02:41:40 +04:00
|
|
|
revision = Revision.new({
|
|
|
|
:identifier => changeset[:commit],
|
2011-04-24 13:55:26 +04:00
|
|
|
:scmid => changeset[:commit],
|
|
|
|
:author => changeset[:author],
|
|
|
|
:time => Time.parse(changeset[:date]),
|
|
|
|
:message => changeset[:description],
|
2011-10-28 08:58:26 +04:00
|
|
|
:paths => files,
|
|
|
|
:parents => changeset[:parents]
|
2011-05-06 17:49:10 +04:00
|
|
|
})
|
2011-05-13 10:03:26 +04:00
|
|
|
if block_given?
|
|
|
|
yield revision
|
|
|
|
else
|
|
|
|
revs << revision
|
|
|
|
end
|
2008-06-29 13:41:42 +04:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-05-06 17:49:33 +04:00
|
|
|
revs
|
2011-05-13 03:44:43 +04:00
|
|
|
rescue ScmCommandAborted => e
|
2012-02-11 02:56:54 +04:00
|
|
|
err_msg = "git log error: #{e.message}"
|
|
|
|
logger.error(err_msg)
|
|
|
|
if block_given?
|
|
|
|
raise CommandFailed, err_msg
|
|
|
|
else
|
|
|
|
revs
|
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2008-06-08 20:28:42 +04:00
|
|
|
def diff(path, identifier_from, identifier_to=nil)
|
2008-03-12 23:28:49 +03:00
|
|
|
path ||= ''
|
2011-03-08 07:50:28 +03:00
|
|
|
cmd_args = []
|
2009-08-16 02:41:40 +04:00
|
|
|
if identifier_to
|
2011-03-08 07:50:28 +03:00
|
|
|
cmd_args << "diff" << "--no-color" << identifier_to << identifier_from
|
2009-08-16 02:41:40 +04:00
|
|
|
else
|
2011-03-08 07:50:28 +03:00
|
|
|
cmd_args << "show" << "--no-color" << identifier_from
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-03-08 07:50:28 +03:00
|
|
|
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) unless path.empty?
|
2008-03-12 23:28:49 +03:00
|
|
|
diff = []
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) do |io|
|
2008-03-12 23:28:49 +03:00
|
|
|
io.each_line do |line|
|
|
|
|
diff << line
|
|
|
|
end
|
|
|
|
end
|
2008-06-08 20:28:42 +04:00
|
|
|
diff
|
2011-03-08 07:50:28 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-03-08 08:17:22 +03:00
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def annotate(path, identifier=nil)
|
|
|
|
identifier = 'HEAD' if identifier.blank?
|
2013-09-18 10:16:55 +04:00
|
|
|
cmd_args = %w|blame --encoding=UTF-8|
|
2011-03-08 08:17:22 +03:00
|
|
|
cmd_args << "-p" << identifier << "--" << scm_iconv(@path_encoding, 'UTF-8', path)
|
2008-03-12 23:28:49 +03:00
|
|
|
blame = Annotate.new
|
2008-03-19 20:51:13 +03:00
|
|
|
content = nil
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) { |io| io.binmode; content = io.read }
|
2008-03-19 20:51:13 +03:00
|
|
|
# git annotates binary files
|
|
|
|
return nil if content.is_binary_data?
|
2010-02-28 15:09:09 +03:00
|
|
|
identifier = ''
|
2010-03-04 00:15:46 +03:00
|
|
|
# git shows commit author on the first occurrence only
|
|
|
|
authors_by_commit = {}
|
2008-03-19 20:51:13 +03:00
|
|
|
content.split("\n").each do |line|
|
2010-02-28 15:09:09 +03:00
|
|
|
if line =~ /^([0-9a-f]{39,40})\s.*/
|
|
|
|
identifier = $1
|
|
|
|
elsif line =~ /^author (.+)/
|
2010-03-04 00:15:46 +03:00
|
|
|
authors_by_commit[identifier] = $1.strip
|
2010-02-28 15:09:09 +03:00
|
|
|
elsif line =~ /^\t(.*)/
|
2011-03-08 08:17:22 +03:00
|
|
|
blame.add_line($1, Revision.new(
|
|
|
|
:identifier => identifier,
|
2011-04-11 09:52:34 +04:00
|
|
|
:revision => identifier,
|
|
|
|
:scmid => identifier,
|
|
|
|
:author => authors_by_commit[identifier]
|
|
|
|
))
|
2010-02-28 15:09:09 +03:00
|
|
|
identifier = ''
|
|
|
|
author = ''
|
|
|
|
end
|
2008-03-19 20:51:13 +03:00
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
blame
|
2011-03-08 08:17:22 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-02-20 04:33:30 +03:00
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def cat(path, identifier=nil)
|
|
|
|
if identifier.nil?
|
|
|
|
identifier = 'HEAD'
|
|
|
|
end
|
2011-03-08 08:17:43 +03:00
|
|
|
cmd_args = %w|show --no-color|
|
|
|
|
cmd_args << "#{identifier}:#{scm_iconv(@path_encoding, 'UTF-8', path)}"
|
2008-03-12 23:28:49 +03:00
|
|
|
cat = nil
|
2012-03-28 15:21:26 +04:00
|
|
|
git_cmd(cmd_args) do |io|
|
2008-03-12 23:28:49 +03:00
|
|
|
io.binmode
|
|
|
|
cat = io.read
|
|
|
|
end
|
|
|
|
cat
|
2011-03-08 08:17:43 +03:00
|
|
|
rescue ScmCommandAborted
|
|
|
|
nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-01-02 12:45:05 +03:00
|
|
|
|
|
|
|
class Revision < Redmine::Scm::Adapters::Revision
|
|
|
|
# Returns the readable identifier
|
|
|
|
def format_identifier
|
|
|
|
identifier[0,8]
|
|
|
|
end
|
|
|
|
end
|
2011-02-20 04:33:30 +03:00
|
|
|
|
2012-03-28 19:40:37 +04:00
|
|
|
def git_cmd(args, options = {}, &block)
|
2011-02-20 04:33:30 +03:00
|
|
|
repo_path = root_url || url
|
2011-07-15 20:32:15 +04:00
|
|
|
full_args = ['--git-dir', repo_path]
|
2011-03-09 02:30:29 +03:00
|
|
|
if self.class.client_version_above?([1, 7, 2])
|
|
|
|
full_args << '-c' << 'core.quotepath=false'
|
2011-04-06 11:16:25 +04:00
|
|
|
full_args << '-c' << 'log.decorate=no'
|
2011-03-09 02:30:29 +03:00
|
|
|
end
|
2011-02-20 04:33:30 +03:00
|
|
|
full_args += args
|
2011-07-15 20:32:15 +04:00
|
|
|
ret = shellout(
|
|
|
|
self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '),
|
2012-03-28 19:40:37 +04:00
|
|
|
options,
|
2011-07-15 20:32:15 +04:00
|
|
|
&block
|
|
|
|
)
|
2011-02-20 04:33:30 +03:00
|
|
|
if $? && $?.exitstatus != 0
|
|
|
|
raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}"
|
|
|
|
end
|
|
|
|
ret
|
|
|
|
end
|
2012-03-28 15:21:26 +04:00
|
|
|
private :git_cmd
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|