Patch #10470 » 0001-Pass-revisions-to-git-log-via-stdin.patch
| 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 | ||
|---|---|---|
|
return @branches if @branches
|
||
|
@branches = []
|
||
|
cmd_args = %w|branch --no-color --verbose --no-abbrev|
|
||
|
scm_cmd(*cmd_args) do |io|
|
||
|
scm_cmd(cmd_args) do |io|
|
||
|
io.each_line do |line|
|
||
|
branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
|
||
|
bran = GitBranch.new(branch_rev[2])
|
||
| ... | ... | |
|
def tags
|
||
|
return @tags if @tags
|
||
|
cmd_args = %w|tag|
|
||
|
scm_cmd(*cmd_args) do |io|
|
||
|
scm_cmd(cmd_args) do |io|
|
||
|
@tags = io.readlines.sort!.map{|t| t.strip}
|
||
|
end
|
||
|
rescue ScmCommandAborted
|
||
| ... | ... | |
|
cmd_args = %w|ls-tree -l|
|
||
|
cmd_args << "HEAD:#{p}" if identifier.nil?
|
||
|
cmd_args << "#{identifier}:#{p}" if identifier
|
||
|
scm_cmd(*cmd_args) do |io|
|
||
|
scm_cmd(cmd_args) do |io|
|
||
|
io.each_line do |line|
|
||
|
e = line.chomp.to_s
|
||
|
if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\t(.+)$/
|
||
| ... | ... | |
|
cmd_args << rev if rev
|
||
|
cmd_args << "--" << path unless path.empty?
|
||
|
lines = []
|
||
|
scm_cmd(*cmd_args) { |io| lines = io.readlines }
|
||
|
scm_cmd(cmd_args) { |io| lines = io.readlines }
|
||
|
begin
|
||
|
id = lines[0].split[1]
|
||
|
author = lines[1].match('Author:\s+(.*)$')[1]
|
||
| ... | ... | |
|
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+b") 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
|
||
|
cmd_args << "--" << scm_iconv(@path_encoding, 'UTF-8', path) unless path.empty?
|
||
|
diff = []
|
||
|
scm_cmd *cmd_args do |io|
|
||
|
scm_cmd cmd_args do |io|
|
||
|
io.each_line do |line|
|
||
|
diff << line
|
||
|
end
|
||
| ... | ... | |
|
cmd_args << "-p" << identifier << "--" << scm_iconv(@path_encoding, 'UTF-8', path)
|
||
|
blame = Annotate.new
|
||
|
content = nil
|
||
|
scm_cmd(*cmd_args) { |io| io.binmode; content = io.read }
|
||
|
scm_cmd(cmd_args) { |io| io.binmode; content = io.read }
|
||
|
# git annotates binary files
|
||
|
return nil if content.is_binary_data?
|
||
|
identifier = ''
|
||
| ... | ... | |
|
cmd_args = %w|show --no-color|
|
||
|
cmd_args << "#{identifier}:#{scm_iconv(@path_encoding, 'UTF-8', path)}"
|
||
|
cat = nil
|
||
|
scm_cmd(*cmd_args) do |io|
|
||
|
scm_cmd(cmd_args) do |io|
|
||
|
io.binmode
|
||
|
cat = io.read
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def scm_cmd(*args, &block)
|
||
|
def scm_cmd(args, options = {}, &block)
|
||
|
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
|
||
|
cmd_args = %w|rev-parse --verify --quiet|
|
||
|
cmd_args << revision
|
||
|
scm_cmd(cmd_args) 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
|
||