Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -21,7 +23,8 @@ require 'redmine/scm/adapters'
module Redmine
module Scm
module Adapters
class AbstractAdapter #:nodoc:
# @private
class AbstractAdapter
include Redmine::Utils::Shell
# raised if scm command exited with error, e.g. unknown revision.
@ -175,7 +178,8 @@ module Redmine
(path[-1,1] == "/") ? path[0..-2] : path
end
private
private
def retrieve_root_url
info = self.info
info ? info.root_url : nil
@ -183,7 +187,7 @@ module Redmine
def target(path, sq=true)
path ||= ''
base = path.match(/^\//) ? root_url : url
base = /^\//.match?(path) ? root_url : url
str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
if sq
str = shell_quote(str)
@ -199,10 +203,6 @@ module Redmine
self.class.shellout(cmd, options, &block)
end
def self.logger
Rails.logger
end
# Path to the file where scm stderr output is logged
# Returns nil if the log file is not writable
def self.stderr_log_file
@ -211,7 +211,7 @@ module Redmine
path = Redmine::Configuration['scm_stderr_log_file'].presence
path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s
if File.exists?(path)
if File.file?(path) && File.writable?(path)
if File.file?(path) && File.writable?(path)
writable = true
else
logger.warn("SCM log file (#{path}) is not writable")
@ -228,37 +228,41 @@ module Redmine
end
@stderr_log_file || nil
end
private_class_method :stderr_log_file
def self.shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
# Capture stderr in a log file
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
# Singleton class method is public
class << self
def logger
Rails.logger
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
block.call(io) if block_given?
def shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
# Capture stderr in a log file
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
yield(io) if block_given?
end
rescue => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end
## If scm command does not exist,
## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
## in production environment.
# rescue Errno::ENOENT => e
rescue Exception => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end
end
@ -267,18 +271,20 @@ module Redmine
q = (Redmine::Platform.mswin? ? '"' : "'")
cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
end
private_class_method :strip_credential
def strip_credential(cmd)
self.class.strip_credential(cmd)
end
def scm_iconv(to, from, str)
return nil if str.nil?
return if str.nil?
return str if to == from && str.encoding.to_s == from
str = str.dup
str.force_encoding(from)
begin
str.encode(to)
rescue Exception => err
rescue => err
logger.error("failed to convert from #{from} to #{to}. #{err}")
nil
end
@ -328,11 +334,11 @@ module Redmine
end
def is_file?
'file' == self.kind
self.kind == 'file'
end
def is_dir?
'dir' == self.kind
self.kind == 'dir'
end
def is_text?

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -43,7 +45,7 @@ module Redmine
end
def scm_command_version
scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
scm_version = scm_version_from_command_line.b
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@ -94,10 +96,9 @@ module Redmine
cmd_args << "-r#{identifier.to_i}"
cmd_args << bzr_target(path)
scm_cmd(*cmd_args) do |io|
prefix_utf8 = "#{url}/#{path}".gsub('\\', '/')
prefix_utf8 = "#{url}/#{path}".tr('\\', '/')
logger.debug "PREFIX: #{prefix_utf8}"
prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8)
prefix.force_encoding('ASCII-8BIT')
prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8).b
re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
io.each_line do |line|
next unless line =~ re
@ -152,7 +153,7 @@ module Redmine
parsing = $1
elsif line =~ /^ (.*)$/
if parsing == 'message'
revision.message << "#{$1}\n"
revision.message += "#{$1}\n"
else
if $1 =~ /^(.*)\s+(\S+)$/
path_locale = $1.strip
@ -247,36 +248,28 @@ module Redmine
end
def self.branch_conf_path(path)
bcp = nil
return if path.nil?
m = path.match(%r{^(.*[/\\])\.bzr.*$})
if m
bcp = m[1]
else
bcp = path
end
bcp.gsub!(%r{[\/\\]$}, "")
if bcp
bcp = File.join(bcp, ".bzr", "branch", "branch.conf")
end
bcp
bcp = (m ? m[1] : path).gsub(%r{[\/\\]$}, "")
File.join(bcp, ".bzr", "branch", "branch.conf")
end
def append_revisions_only
return @aro if ! @aro.nil?
return @aro unless @aro.nil?
@aro = false
bcp = self.class.branch_conf_path(url)
if bcp && File.exist?(bcp)
begin
f = File::open(bcp, "r")
f = File.open(bcp, "r")
cnt = 0
f.each_line do |line|
l = line.chomp.to_s
if l =~ /^\s*append_revisions_only\s*=\s*(\w+)\s*$/
str_aro = $1
if str_aro.upcase == "TRUE"
if str_aro.casecmp("TRUE") == 0
@aro = true
cnt += 1
elsif str_aro.upcase == "FALSE"
elsif str_aro.casecmp("FALSE") == 0
@aro = false
cnt += 1
end
@ -301,7 +294,7 @@ module Redmine
full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
end
ret = shellout(
self.class.sq_bin + ' ' +
self.class.sq_bin + ' ' +
full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
&block
)
@ -320,7 +313,7 @@ module Redmine
full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
end
ret = shellout(
self.class.sq_bin + ' ' +
self.class.sq_bin + ' ' +
full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
&block
)

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,7 +20,8 @@
module Redmine
module Scm
module Adapters
class CommandFailed < StandardError #:nodoc:
# @private
class CommandFailed < StandardError
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -43,7 +45,7 @@ module Redmine
end
def scm_command_version
scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
scm_version = scm_version_from_command_line.b
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)}m)
m[2].scan(%r{\d+}).collect(&:to_i)
end
@ -61,7 +63,7 @@ module Redmine
# password -> unnecessary too
def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil)
@path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
@path_encoding = path_encoding.presence || 'UTF-8'
@url = url
# TODO: better Exception here (IllegalArgumentException)
raise CommandFailed if root_url.blank?
@ -91,7 +93,7 @@ module Redmine
def entries(path=nil, identifier=nil, options={})
logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
path_locale = scm_iconv(@path_encoding, 'UTF-8', path)
path_locale.force_encoding("ASCII-8BIT")
path_locale = path_locale.b
entries = Entries.new
cmd_args = %w|-q rls -e|
cmd_args << "-D" << time_to_cvstime_rlog(identifier) if identifier
@ -159,7 +161,7 @@ module Redmine
cmd_args << path_with_project_utf8
scm_cmd(*cmd_args) do |io|
state = "entry_start"
commit_log = String.new
commit_log = ""
revision = nil
date = nil
author = nil
@ -168,23 +170,23 @@ module Redmine
file_state = nil
branch_map = nil
io.each_line() do |line|
if state != "revision" && /^#{ENDLOG}/ =~ line
commit_log = String.new
if state != "revision" && /^#{ENDLOG}/.match?(line)
commit_log = ""
revision = nil
state = "entry_start"
end
if state == "entry_start"
branch_map = Hash.new
branch_map = {}
if /^RCS file: #{Regexp.escape(root_url_path)}\/#{Regexp.escape(path_with_project_locale)}(.+),v$/ =~ line
entry_path = normalize_cvs_path($1)
entry_name = normalize_path(File.basename($1))
logger.debug("Path #{entry_path} <=> Name #{entry_name}")
elsif /^head: (.+)$/ =~ line
entry_headRev = $1 #unless entry.nil?
elsif /^symbolic names:/ =~ line
state = "symbolic" #unless entry.nil?
elsif /^#{STARTLOG}/ =~ line
commit_log = String.new
entry_headRev = $1
elsif /^symbolic names:/.match?(line)
state = "symbolic"
elsif /^#{STARTLOG}/.match?(line)
commit_log = ""
state = "revision"
end
next
@ -228,7 +230,7 @@ module Redmine
}]
})
end
commit_log = String.new
commit_log = ""
revision = nil
if /^#{ENDLOG}/ =~ line
state = "entry_start"
@ -241,15 +243,14 @@ module Redmine
elsif /^revision (\d+(?:\.\d+)+).*$/ =~ line
revision = $1
elsif /^date:\s+(\d+.\d+.\d+\s+\d+:\d+:\d+)/ =~ line
date = Time.parse($1)
date = Time.parse($1)
line_utf8 = scm_iconv('UTF-8', options[:log_encoding], line)
author_utf8 = /author: ([^;]+)/.match(line_utf8)[1]
author = scm_iconv(options[:log_encoding], 'UTF-8', author_utf8)
file_state = /state: ([^;]+)/.match(line)[1]
# TODO:
# linechanges only available in CVS....
# maybe a feature our SVN implementation.
# I'm sure, they are useful for stats or something else
# TODO: linechanges only available in CVS....
# maybe a feature our SVN implementation.
# I'm sure, they are useful for stats or something else
# linechanges =/lines: \+(\d+) -(\d+)/.match(line)
# unless linechanges.nil?
# version.line_plus = linechanges[1]
@ -259,7 +260,7 @@ module Redmine
# version.line_minus = 0
# end
else
commit_log << line unless line =~ /^\*\*\* empty log message \*\*\*/
commit_log += line unless line =~ /^\*\*\* empty log message \*\*\*/
end
end
end
@ -338,9 +339,8 @@ module Redmine
# convert a date/time into the CVS-format
def time_to_cvstime(time)
return nil if time.nil?
time = Time.now if (time.kind_of?(String) && time == 'HEAD')
unless time.kind_of? Time
time = Time.now if (time.is_a?(String) && time == 'HEAD')
unless time.is_a?(Time)
time = Time.parse(time)
end
return time_to_cvstime_rlog(time)
@ -399,10 +399,6 @@ module Redmine
parseRevision()
end
def branchPoint
return @base
end
def branchVersion
if isBranchRevision
return @base+"."+@branchid
@ -428,6 +424,7 @@ module Redmine
end
private
def buildRevision(rev)
if rev == 0
if @branchid.nil?
@ -443,7 +440,7 @@ module Redmine
end
# Interpretiert die cvs revisionsnummern wie z.b. 1.14 oder 1.3.0.15
def parseRevision()
def parseRevision
pieces = @complete_rev.split(".")
@revision = pieces.last.to_i
baseSize = 1

View file

@ -1,239 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# 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.
#
# 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.
#
# 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'
require 'rexml/document'
module Redmine
module Scm
module Adapters
class DarcsAdapter < AbstractAdapter
# Darcs executable name
DARCS_BIN = Redmine::Configuration['scm_darcs_command'] || "darcs"
class << self
def client_command
@@bin ||= DARCS_BIN
end
def sq_bin
@@sq_bin ||= shell_quote_command
end
def client_version
@@client_version ||= (darcs_binary_version || [])
end
def client_available
!client_version.empty?
end
def darcs_binary_version
darcsversion = darcs_binary_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
end
def darcs_binary_version_from_command_line
shellout("#{sq_bin} --version") { |io| io.read }.to_s
end
end
def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil)
@url = url
@root_url = url
end
def supports_cat?
# cat supported in darcs 2.0.0 and higher
self.class.client_version_above?([2, 0, 0])
end
# Get info about the darcs repository
def info
rev = revisions(nil,nil,nil,{:limit => 1})
rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil
end
# Returns an Entries collection
# or nil if the given path doesn't exist in the repository
def entries(path=nil, identifier=nil, options={})
path_prefix = (path.blank? ? '' : "#{path}/")
if path.blank?
path = ( self.class.client_version_above?([2, 2, 0]) ? @url : '.' )
end
entries = Entries.new
cmd = "#{self.class.sq_bin} annotate --repodir #{shell_quote @url} --xml-output"
cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier
cmd << " #{shell_quote path}"
shellout(cmd) do |io|
begin
doc = REXML::Document.new(io)
if doc.root.name == 'directory'
doc.elements.each('directory/*') do |element|
next unless ['file', 'directory'].include? element.name
entries << entry_from_xml(element, path_prefix)
end
elsif doc.root.name == 'file'
entries << entry_from_xml(doc.root, path_prefix)
end
rescue
end
end
return nil if $? && $?.exitstatus != 0
entries.compact!
entries.sort_by_name
end
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
path = '.' if path.blank?
revisions = Revisions.new
cmd = "#{self.class.sq_bin} changes --repodir #{shell_quote @url} --xml-output"
cmd << " --from-match #{shell_quote("hash #{identifier_from}")}" if identifier_from
cmd << " --last #{options[:limit].to_i}" if options[:limit]
shellout(cmd) do |io|
begin
doc = REXML::Document.new(io)
doc.elements.each("changelog/patch") do |patch|
message = patch.elements['name'].text
message << "\n" + patch.elements['comment'].text.gsub(/\*\*\*END OF DESCRIPTION\*\*\*.*\z/m, '') if patch.elements['comment']
revisions << Revision.new({:identifier => nil,
:author => patch.attributes['author'],
:scmid => patch.attributes['hash'],
:time => Time.parse(patch.attributes['local_date']),
:message => message,
:paths => (options[:with_path] ? get_paths_for_patch(patch.attributes['hash']) : nil)
})
end
rescue
end
end
return nil if $? && $?.exitstatus != 0
revisions
end
def diff(path, identifier_from, identifier_to=nil)
path = '*' if path.blank?
cmd = "#{self.class.sq_bin} diff --repodir #{shell_quote @url}"
if identifier_to.nil?
cmd << " --match #{shell_quote("hash #{identifier_from}")}"
else
cmd << " --to-match #{shell_quote("hash #{identifier_from}")}"
cmd << " --from-match #{shell_quote("hash #{identifier_to}")}"
end
cmd << " -u #{shell_quote path}"
diff = []
shellout(cmd) do |io|
io.each_line do |line|
diff << line
end
end
return nil if $? && $?.exitstatus != 0
diff
end
def cat(path, identifier=nil)
cmd = "#{self.class.sq_bin} show content --repodir #{shell_quote @url}"
cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier
cmd << " #{shell_quote path}"
cat = nil
shellout(cmd) do |io|
io.binmode
cat = io.read
end
return nil if $? && $?.exitstatus != 0
cat
end
private
# Returns an Entry from the given XML element
# or nil if the entry was deleted
def entry_from_xml(element, path_prefix)
modified_element = element.elements['modified']
if modified_element.elements['modified_how'].text.match(/removed/)
return nil
end
Entry.new({:name => element.attributes['name'],
:path => path_prefix + element.attributes['name'],
:kind => element.name == 'file' ? 'file' : 'dir',
:size => nil,
:lastrev => Revision.new({
:identifier => nil,
:scmid => modified_element.elements['patch'].attributes['hash']
})
})
end
def get_paths_for_patch(hash)
paths = get_paths_for_patch_raw(hash)
if self.class.client_version_above?([2, 4])
orig_paths = paths
paths = []
add_paths = []
add_paths_name = []
mod_paths = []
other_paths = []
orig_paths.each do |path|
if path[:action] == 'A'
add_paths << path
add_paths_name << path[:path]
elsif path[:action] == 'M'
mod_paths << path
else
other_paths << path
end
end
add_paths_name.each do |add_path|
mod_paths.delete_if { |m| m[:path] == add_path }
end
paths.concat add_paths
paths.concat mod_paths
paths.concat other_paths
end
paths
end
# Retrieve changed paths for a single patch
def get_paths_for_patch_raw(hash)
cmd = "#{self.class.sq_bin} annotate --repodir #{shell_quote @url} --summary --xml-output"
cmd << " --match #{shell_quote("hash #{hash}")} "
paths = []
shellout(cmd) do |io|
begin
# Darcs xml output has multiple root elements in this case (tested with darcs 1.0.7)
# A root element is added so that REXML doesn't raise an error
doc = REXML::Document.new("<fake_root>" + io.read + "</fake_root>")
doc.elements.each('fake_root/summary/*') do |modif|
paths << {:action => modif.name[0,1].upcase,
:path => "/" + modif.text.chomp.gsub(/^\s*/, '')
}
end
rescue
end
end
paths
rescue CommandFailed
paths
end
end
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# FileSystem adapter
# File written by Paul Rivier, at Demotera.
@ -107,7 +109,7 @@ module Redmine
# Here we do not shell-out, so we do not want quotes.
def target(path=nil)
# Prevent the use of ..
if path and !path.match(/(^|\/)\.\.(\/|$)/)
if path and !/(^|\/)\.\.(\/|$)/.match?(path)
return "#{self.url}#{without_leading_slash(path)}"
end
return self.url

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -47,7 +49,7 @@ module Redmine
end
def scm_command_version
scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
scm_version = scm_version_from_command_line.b
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@ -68,11 +70,9 @@ module Redmine
end
def info
begin
Info.new(:root_url => url, :lastrev => lastrev('',nil))
rescue
nil
end
Info.new(:root_url => url, :lastrev => lastrev('',nil))
rescue
nil
end
def branches
@ -82,8 +82,8 @@ module Redmine
git_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])
next unless branch_rev
bran = GitBranch.new(scm_iconv('UTF-8', @path_encoding, branch_rev[2]))
bran.revision = branch_rev[3]
bran.scmid = branch_rev[3]
bran.is_default = ( branch_rev[1] == '*' )
@ -100,7 +100,7 @@ module Redmine
@tags = []
cmd_args = %w|tag|
git_cmd(cmd_args) do |io|
@tags = io.readlines.sort!.map{|t| t.strip}
@tags = io.readlines.sort!.map{|t| scm_iconv('UTF-8', @path_encoding, t.strip)}
end
@tags
rescue ScmCommandAborted
@ -109,11 +109,11 @@ module Redmine
def default_branch
bras = self.branches
return nil if bras.nil?
default_bras = bras.select{|x| x.is_default == true}
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'
return unless bras
default_bras = bras.detect{|x| x.is_default == true}
return default_bras.to_s if default_bras
master_bras = bras.detect{|x| x.to_s == 'master'}
master_bras ? 'master' : bras.first.to_s
end
def entry(path=nil, identifier=nil)
@ -136,8 +136,9 @@ module Redmine
p = scm_iconv(@path_encoding, 'UTF-8', path)
entries = Entries.new
cmd_args = %w|ls-tree -l|
cmd_args << "HEAD:#{p}" if identifier.nil?
cmd_args << "#{identifier}:#{p}" if identifier
identifier = 'HEAD' if identifier.nil?
git_identifier = scm_iconv(@path_encoding, 'UTF-8', identifier)
cmd_args << "#{git_identifier}:#{p}"
git_cmd(cmd_args) do |io|
io.each_line do |line|
e = line.chomp.to_s
@ -198,13 +199,19 @@ module Redmine
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents --stdin|
cmd_args << '--no-renames' if self.class.client_version_above?([2, 9])
cmd_args << "--reverse" if options[:reverse]
cmd_args << "-n" << "#{options[:limit].to_i}" if options[:limit]
cmd_args << "-n" << options[:limit].to_i.to_s if options[:limit]
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
revisions << +""
if identifier_from
git_identifier_from = scm_iconv(@path_encoding, 'UTF-8', identifier_from)
revisions[0] << "#{git_identifier_from}.." if identifier_from
end
if identifier_to
git_identifier_to = scm_iconv(@path_encoding, 'UTF-8', identifier_to)
revisions[0] << git_identifier_to.to_s if identifier_to
end
else
unless options[:includes].blank?
revisions += options[:includes]
@ -220,14 +227,15 @@ module Redmine
io.close_write
files=[]
changeset = {}
parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
# 0: not parsing desc or files, 1: parsing desc, 2: parsing files
parsing_descr = 0
io.each_line do |line|
if line =~ /^commit ([0-9a-f]{40})(( [0-9a-f]{40})*)$/
key = "commit"
value = $1
parents_str = $2
if (parsing_descr == 1 || parsing_descr == 2)
if [1, 2].include?(parsing_descr)
parsing_descr = 0
revision = Revision.new({
:identifier => changeset[:commit],
@ -260,16 +268,16 @@ module Redmine
end
elsif (parsing_descr == 0) && line.chomp.to_s == ""
parsing_descr = 1
changeset[:description] = ""
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
changeset[:description] = +""
elsif [1, 2].include?(parsing_descr) &&
line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $2
p = scm_iconv('UTF-8', @path_encoding, filepath)
files << {:action => fileaction, :path => p}
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
elsif [1, 2].include?(parsing_descr) &&
line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $3
@ -333,8 +341,9 @@ module Redmine
def annotate(path, identifier=nil)
identifier = 'HEAD' if identifier.blank?
git_identifier = scm_iconv(@path_encoding, 'UTF-8', identifier)
cmd_args = %w|blame --encoding=UTF-8|
cmd_args << "-p" << identifier << "--" << scm_iconv(@path_encoding, 'UTF-8', path)
cmd_args << "-p" << git_identifier << "--" << scm_iconv(@path_encoding, 'UTF-8', path)
blame = Annotate.new
content = nil
git_cmd(cmd_args) { |io| io.binmode; content = io.read }
@ -365,11 +374,10 @@ module Redmine
end
def cat(path, identifier=nil)
if identifier.nil?
identifier = 'HEAD'
end
identifier = 'HEAD' if identifier.nil?
git_identifier = scm_iconv(@path_encoding, 'UTF-8', identifier)
cmd_args = %w|show --no-color|
cmd_args << "#{identifier}:#{scm_iconv(@path_encoding, 'UTF-8', path)}"
cmd_args << "#{git_identifier}:#{scm_iconv(@path_encoding, 'UTF-8', path)}"
cat = nil
git_cmd(cmd_args) do |io|
io.binmode

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -56,7 +58,7 @@ module Redmine
# The hg version is expressed either as a
# release number (eg 0.9.5 or 1.0) or as a revision
# id composed of 12 hexa characters.
theversion = hgversion_from_command_line.dup.force_encoding('ASCII-8BIT')
theversion = hgversion_from_command_line.b
if m = theversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@ -90,7 +92,7 @@ module Redmine
:lastrev => Revision.new(:revision => tip['revision'],
:scmid => tip['node']))
# rescue HgCommandAborted
rescue Exception => e
rescue => e
logger.error "hg: error during getting info: #{e.message}"
nil
end
@ -133,6 +135,7 @@ module Redmine
begin
@summary = parse_xml(output)['rhsummary']
rescue
# do nothing
end
end
end
@ -146,6 +149,7 @@ module Redmine
begin
parse_xml(output)['rhmanifest']['repository']['manifest']
rescue
# do nothing
end
end
path_prefix = path.blank? ? '' : with_trailling_slash(path)
@ -191,6 +195,7 @@ module Redmine
# Mercurial < 1.5 does not support footer template for '</log>'
parse_xml("#{output}</log>")['log']
rescue
# do nothing
end
end
as_ary(log['logentry']).each do |le|
@ -201,19 +206,25 @@ module Redmine
end
cpmap = Hash[*cpalist.flatten]
paths = as_ary(le['paths']['path']).map do |e|
p = scm_iconv('UTF-8', @path_encoding, CGI.unescape(e['__content__']) )
p = scm_iconv('UTF-8', @path_encoding, CGI.unescape(e['__content__']))
{:action => e['action'],
:path => with_leading_slash(p),
:from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil),
:from_revision => (cpmap.member?(p) ? le['node'] : nil)}
end.sort { |a, b| a[:path] <=> b[:path] }
end
paths.sort_by!{|e| e[:path]}
parents_ary = []
as_ary(le['parents']['parent']).map do |par|
parents_ary << par['__content__'] if par['__content__'] != "0000000000000000000000000000000000000000"
end
yield Revision.new(:revision => le['revision'],
:scmid => le['node'],
:author => (le['author']['__content__'] rescue ''),
:author =>
(begin
le['author']['__content__']
rescue
''
end),
:time => Time.parse(le['date']['__content__']),
:message => le['msg']['__content__'],
:paths => paths,
@ -243,7 +254,7 @@ module Redmine
hg_args << '--' << CGI.escape(hgtarget(p))
end
diff = []
hg *hg_args do |io|
hg(*hg_args) do |io|
io.each_line do |line|
diff << line
end
@ -268,8 +279,7 @@ module Redmine
blame = Annotate.new
hg 'rhannotate', '-ncu', "-r#{CGI.escape(hgrev(identifier))}", '--', hgtarget(p) do |io|
io.each_line do |line|
line.force_encoding('ASCII-8BIT')
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
next unless line.b =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
:identifier => $3)
blame.add_line($4.rstrip, r)
@ -296,10 +306,10 @@ module Redmine
# Runs 'hg' command with the given args
def hg(*args, &block)
# as of hg 4.4.1, early parsing of bool options is not terminated at '--'
if args.any? { |s| s =~ HG_EARLY_BOOL_ARG }
if args.any? { |s| HG_EARLY_BOOL_ARG.match?(s) }
raise HgCommandArgumentError, "malicious command argument detected"
end
if args.take_while { |s| s != '--' }.any? { |s| s =~ HG_EARLY_LIST_ARG }
if args.take_while { |s| s != '--' }.any? { |s| HG_EARLY_LIST_ARG.match?(s) }
raise HgCommandArgumentError, "malicious command argument detected"
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -46,7 +48,7 @@ module Redmine
end
def svn_binary_version
scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
scm_version = scm_version_from_command_line.b
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@ -59,7 +61,7 @@ module Redmine
# Get info about the svn repository
def info
cmd = "#{self.class.sq_bin} info --xml #{target}"
cmd = +"#{self.class.sq_bin} info --xml #{target}"
cmd << credentials_string
info = nil
shellout(cmd) do |io|
@ -89,7 +91,7 @@ module Redmine
path ||= ''
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
entries = Entries.new
cmd = "#{self.class.sq_bin} list --xml #{target(path)}@#{identifier}"
cmd = +"#{self.class.sq_bin} list --xml #{target(path)}@#{identifier}"
cmd << credentials_string
shellout(cmd) do |io|
output = io.read.force_encoding('UTF-8')
@ -113,7 +115,7 @@ module Redmine
})
})
end
rescue Exception => e
rescue => e
logger.error("Error parsing svn output: #{e.message}")
logger.error("Output was:\n #{output}")
end
@ -128,7 +130,7 @@ module Redmine
return nil unless self.class.client_version_above?([1, 5, 0])
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{self.class.sq_bin} proplist --verbose --xml #{target(path)}@#{identifier}"
cmd = +"#{self.class.sq_bin} proplist --verbose --xml #{target(path)}@#{identifier}"
cmd << credentials_string
properties = {}
shellout(cmd) do |io|
@ -136,7 +138,7 @@ module Redmine
begin
doc = parse_xml(output)
each_xml_element(doc['properties']['target'], 'property') do |property|
properties[ property['name'] ] = property['__content__'].to_s
properties[property['name']] = property['__content__'].to_s
end
rescue
end
@ -150,7 +152,7 @@ module Redmine
identifier_from = (identifier_from && identifier_from.to_i > 0) ? identifier_from.to_i : "HEAD"
identifier_to = (identifier_to && identifier_to.to_i > 0) ? identifier_to.to_i : 1
revisions = Revisions.new
cmd = "#{self.class.sq_bin} log --xml -r #{identifier_from}:#{identifier_to}"
cmd = +"#{self.class.sq_bin} log --xml -r #{identifier_from}:#{identifier_to}"
cmd << credentials_string
cmd << " --verbose " if options[:with_paths]
cmd << " --limit #{options[:limit].to_i}" if options[:limit]
@ -168,7 +170,7 @@ module Redmine
:from_revision => path['copyfrom-rev']
}
end if logentry['paths'] && logentry['paths']['path']
paths.sort! { |x,y| x[:path] <=> y[:path] }
paths.sort_by! {|e| e[:path]}
revisions << Revision.new({:identifier => logentry['revision'],
:author => (logentry['author'] ? logentry['author']['__content__'] : ""),
@ -190,7 +192,7 @@ module Redmine
identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : (identifier_from.to_i - 1)
cmd = "#{self.class.sq_bin} diff -r "
cmd = +"#{self.class.sq_bin} diff -r "
cmd << "#{identifier_to}:"
cmd << "#{identifier_from}"
cmd << " #{target(path)}@#{identifier_from}"
@ -207,7 +209,7 @@ module Redmine
def cat(path, identifier=nil)
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{self.class.sq_bin} cat #{target(path)}@#{identifier}"
cmd = +"#{self.class.sq_bin} cat #{target(path)}@#{identifier}"
cmd << credentials_string
cat = nil
shellout(cmd) do |io|
@ -220,7 +222,7 @@ module Redmine
def annotate(path, identifier=nil)
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{self.class.sq_bin} blame #{target(path)}@#{identifier}"
cmd = +"#{self.class.sq_bin} blame #{target(path)}@#{identifier}"
cmd << credentials_string
blame = Annotate.new
shellout(cmd) do |io|
@ -242,7 +244,7 @@ module Redmine
private
def credentials_string
str = ''
str = +''
str << " --username #{shell_quote(@login)}" unless @login.blank?
str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?
str << " --no-auth-cache --non-interactive"
@ -265,7 +267,7 @@ module Redmine
end
def target(path = '')
base = path.match(/^\//) ? root_url : url
base = /^\//.match?(path) ? root_url : url
uri = "#{base}/#{path}"
uri = URI.escape(URI.escape(uri), '[]')
shell_quote(uri.gsub(/[?<>\*]/, ''))

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Redmine
module Scm
class Base