Project

General

Profile

Defect #8857 » 0001-Pass-revisions-to-git-log-via-stdin.patch

Minimal changes to pass all revisions to git-log via stdin - Jeremy Bopp, 2012-03-15 23:59

View differences:

lib/redmine/scm/adapters/abstract_adapter.rb
self.class.logger
end
def shellout(cmd, &block)
self.class.shellout(cmd, &block)
def shellout(cmd, options = {}, &block)
self.class.shellout(cmd, options, &block)
end
def self.logger
Rails.logger
end
def self.shellout(cmd, &block)
def self.shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
end
......
cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}"
end
begin
if RUBY_VERSION < '1.9'
mode = "r+"
else
mode = "r+:ASCII-8BIT"
end
mode = (options[:mode] || 'r').to_s
IO.popen(cmd, mode) do |io|
io.close_write
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
block.call(io) if block_given?
end
## If scm command does not exist,
lib/redmine/scm/adapters/git_adapter.rb
def revisions(path, identifier_from, identifier_to, options={})
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 << "-n" << "#{options[:limit].to_i}" if options[:limit]
from_to = ""
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
revisions = []
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?
revisions << ""
revisions[0] << "#{identifier_from}.." if identifier_from
revisions[0] << "#{identifier_to}" if identifier_to
else
cmd_args += options[:includes] unless options[:includes].blank?
unless options[:includes].blank?
revisions += ignore_missing_revisions(options[:includes])
end
unless options[:excludes].blank?
cmd_args << "--not"
cmd_args += options[:excludes]
revisions +=
ignore_missing_revisions(options[:excludes]).map{|r| "^#{r}"}
end
end
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) if path && !path.empty?
scm_cmd *cmd_args do |io|
scm_cmd(*cmd_args, :mode => "r+") do |io|
io.puts(revisions.join("\n"))
io.close_write
files=[]
changeset = {}
parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
......
end
def scm_cmd(*args, &block)
options = args.last.kind_of?(Hash) ? args.pop : {}
repo_path = root_url || url
full_args = ['--git-dir', repo_path]
if self.class.client_version_above?([1, 7, 2])
......
full_args += args
ret = shellout(
self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '),
options,
&block
)
if $? && $?.exitstatus != 0
......
ret
end
private :scm_cmd
# Return an array containing only the given revisions that exist in the
# repository.
#
# NOTE:
# This can be removed once the minimum supported Git version supports
# the --ignore-missing option for git-log and #revisions is modified to
# use that option.
def ignore_missing_revisions(revisions)
revisions.select do |revision|
begin
scm_cmd(*%w|rev-parse --verify --quiet|, revision) do |io|
# Read and discard the output in order to make the command
# happy.
io.read
end
true
rescue ScmCommandAborted
false
end
end
end
private :ignore_missing_revisions
end
end
end
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
end
def test_revisions_invalid_rev_excludes
assert_equal [],
@adapter.revisions('', nil, nil,
{:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']})
assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
@adapter.revisions('', nil, nil,
{:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']}) do |rev|
revs1 << rev
end
revs1 = @adapter.revisions('', nil, nil,
{:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']})
assert_equal 15, revs1.length
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier
revs2 = []
@adapter.revisions('', nil, nil,
{:reverse => true,
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
:excludes => ['0123abcd4567']}) do |rev|
revs2 << rev
end
assert_equal 15, revs2.length
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
end
def test_getting_revisions_with_spaces_in_filename
(7-7/8)