scm: git: use stdin instead of command line in "git log" (#10470)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9282 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-03-28 15:40:37 +00:00
parent fbe959b2a8
commit 3e11f9abfe
2 changed files with 20 additions and 15 deletions

View File

@ -206,15 +206,15 @@ module Redmine
self.class.logger self.class.logger
end end
def shellout(cmd, &block) def shellout(cmd, options = {}, &block)
self.class.shellout(cmd, &block) self.class.shellout(cmd, options, &block)
end end
def self.logger def self.logger
Rails.logger Rails.logger
end end
def self.shellout(cmd, &block) def self.shellout(cmd, options = {}, &block)
if logger && logger.debug? if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}" logger.debug "Shelling out: #{strip_credential(cmd)}"
end end
@ -226,7 +226,7 @@ module Redmine
mode = "r+" mode = "r+"
IO.popen(cmd, mode) do |io| IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write io.close_write unless options[:write_stdin]
block.call(io) if block_given? block.call(io) if block_given?
end end
## If scm command does not exist, ## If scm command does not exist,

View File

@ -197,24 +197,28 @@ module Redmine
def revisions(path, identifier_from, identifier_to, options={}) def revisions(path, identifier_from, identifier_to, options={})
revs = Revisions.new revs = Revisions.new
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents| cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin|
cmd_args << "--reverse" if options[:reverse] cmd_args << "--reverse" if options[:reverse]
cmd_args << "-n" << "#{options[:limit].to_i}" if options[:limit] cmd_args << "-n" << "#{options[:limit].to_i}" if options[:limit]
from_to = ""
if identifier_from || identifier_to
from_to << "#{identifier_from}.." if identifier_from
from_to << "#{identifier_to}" if identifier_to
cmd_args << from_to if !from_to.empty?
else
cmd_args += options[:includes] unless options[:includes].blank?
unless options[:excludes].blank?
cmd_args << "--not"
cmd_args += options[:excludes]
end
end
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty? cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
revisions = []
if identifier_from || identifier_to
revisions << ""
revisions[0] << "#{identifier_from}.." if identifier_from
revisions[0] << "#{identifier_to}" if identifier_to
else
unless options[:includes].blank?
revisions += options[:includes]
end
unless options[:excludes].blank?
revisions += options[:excludes].map{|r| "^#{r}"}
end
end
git_cmd(cmd_args) do |io| git_cmd(cmd_args, {:write_stdin => true}) do |io|
io.binmode
io.puts(revisions.join("\n"))
io.close_write
files=[] files=[]
changeset = {} changeset = {}
parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
@ -383,7 +387,7 @@ module Redmine
end end
end end
def git_cmd(args, &block) def git_cmd(args, options = {}, &block)
repo_path = root_url || url repo_path = root_url || url
full_args = ['--git-dir', repo_path] full_args = ['--git-dir', repo_path]
if self.class.client_version_above?([1, 7, 2]) if self.class.client_version_above?([1, 7, 2])
@ -393,6 +397,7 @@ module Redmine
full_args += args full_args += args
ret = shellout( ret = shellout(
self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '),
options,
&block &block
) )
if $? && $?.exitstatus != 0 if $? && $?.exitstatus != 0