scm: git: refactor lastrev() in adapter.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4963 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-02-28 14:12:24 +00:00
parent 06f078a813
commit 06c9eea67a

View File

@ -127,14 +127,13 @@ module Redmine
entries.sort_by_name entries.sort_by_name
end end
def lastrev(path,rev) def lastrev(path, rev)
return nil if path.nil? return nil if path.nil?
cmd = "#{self.class.sq_bin} --git-dir #{target('')} log --no-color --date=iso --pretty=fuller --no-merges -n 1 " cmd_args = %w|log --no-color --date=iso --pretty=fuller --no-merges -n 1|
cmd << " #{shell_quote rev} " if rev cmd_args << rev if rev
cmd << "-- #{shell_quote path} " unless path.empty? cmd_args << "--" << path unless path.empty?
lines = [] lines = []
shellout(cmd) { |io| lines = io.readlines } scm_cmd(*cmd_args) { |io| lines = io.readlines }
return nil if $? && $?.exitstatus != 0
begin begin
id = lines[0].split[1] id = lines[0].split[1]
author = lines[1].match('Author:\s+(.*)$')[1] author = lines[1].match('Author:\s+(.*)$')[1]
@ -147,11 +146,13 @@ module Redmine
:time => time, :time => time,
:message => nil, :message => nil,
:paths => nil :paths => nil
}) })
rescue NoMethodError => e rescue NoMethodError => e
logger.error("The revision '#{path}' has a wrong format") logger.error("The revision '#{path}' has a wrong format")
return nil return nil
end end
rescue ScmCommandAborted
nil
end end
def revisions(path, identifier_from, identifier_to, options={}) def revisions(path, identifier_from, identifier_to, options={})
@ -165,7 +166,7 @@ module Redmine
from_to << "#{identifier_to}" if identifier_to from_to << "#{identifier_to}" if identifier_to
cmd_args << from_to if !from_to.empty? cmd_args << from_to if !from_to.empty?
cmd_args << "--since=#{options[:since].strftime("%Y-%m-%d %H:%M:%S")}" if options[:since] cmd_args << "--since=#{options[:since].strftime("%Y-%m-%d %H:%M:%S")}" if options[:since]
cmd_args << "--" << "#{path}" if path && !path.empty? cmd_args << "--" << path if path && !path.empty?
scm_cmd *cmd_args do |io| scm_cmd *cmd_args do |io|
files=[] files=[]