Adds MercurialAdapter.client_version and prevent @hg --version@ to be called on each request.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1628 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
12fbd06c02
commit
29fb8db936
|
@ -28,6 +28,39 @@ module Redmine
|
|||
TEMPLATE_NAME = "hg-template"
|
||||
TEMPLATE_EXTENSION = "tmpl"
|
||||
|
||||
class << self
|
||||
def client_version
|
||||
@@client_version ||= (hgversion || 'Unknown version')
|
||||
end
|
||||
|
||||
def hgversion
|
||||
# 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
|
||||
if theversion.match(/^\d+(\.\d+)+/)
|
||||
theversion.split(".").collect(&:to_i)
|
||||
end
|
||||
end
|
||||
|
||||
def hgversion_from_command_line
|
||||
%x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
|
||||
end
|
||||
|
||||
def template_path
|
||||
@@template_path ||= template_path_for(client_version)
|
||||
end
|
||||
|
||||
def template_path_for(version)
|
||||
if version.is_a?(String) or ((version <=> [0,9,5]) > 0)
|
||||
ver = "1.0"
|
||||
else
|
||||
ver = "0.9.5"
|
||||
end
|
||||
"#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
|
||||
end
|
||||
end
|
||||
|
||||
def info
|
||||
cmd = "#{HG_BIN} -R #{target('')} root"
|
||||
root_url = nil
|
||||
|
@ -72,7 +105,7 @@ module Redmine
|
|||
# makes Mercurial produce a xml output.
|
||||
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
|
||||
revisions = Revisions.new
|
||||
cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{self.template_path}"
|
||||
cmd = "#{HG_BIN} --debug --encoding utf8 -R #{target('')} log -C --style #{self.class.template_path}"
|
||||
if identifier_from && identifier_to
|
||||
cmd << " -r #{identifier_from.to_i}:#{identifier_to.to_i}"
|
||||
elsif identifier_from
|
||||
|
@ -166,35 +199,6 @@ module Redmine
|
|||
return nil if $? && $?.exitstatus != 0
|
||||
blame
|
||||
end
|
||||
|
||||
# The hg version 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.
|
||||
def hgversion
|
||||
theversion = hgversion_from_command_line
|
||||
if theversion.match(/^\d+(\.\d+)+/)
|
||||
theversion.split(".").collect(&:to_i)
|
||||
# elsif match = theversion.match(/[[:xdigit:]]{12}/)
|
||||
# match[0]
|
||||
else
|
||||
"Unknown version"
|
||||
end
|
||||
end
|
||||
|
||||
def template_path
|
||||
@template ||= begin
|
||||
if hgversion.is_a?(String) or ((hgversion <=> [0,9,5]) > 0)
|
||||
ver = "1.0"
|
||||
else
|
||||
ver = "0.9.5"
|
||||
end
|
||||
"#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}"
|
||||
end
|
||||
end
|
||||
|
||||
def hgversion_from_command_line
|
||||
@hgversion ||= %x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,37 +10,41 @@ begin
|
|||
|
||||
REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
|
||||
|
||||
def test_hgversion
|
||||
to_test = { "0.9.5" => [0,9,5],
|
||||
"1.0" => [1,0],
|
||||
"1e4ddc9ac9f7+20080325" => nil,
|
||||
"1.0.1+20080525" => [1,0,1],
|
||||
"1916e629a29d" => nil}
|
||||
|
||||
def test_version_template_0_9_5
|
||||
# 0.9.5
|
||||
test_version_template_for("0.9.5", [0,9,5], "0.9.5")
|
||||
to_test.each do |s, v|
|
||||
test_hgversion_for(s, v)
|
||||
end
|
||||
end
|
||||
|
||||
def test_version_template_1_0
|
||||
# 1.0
|
||||
test_version_template_for("1.0", [1,0], "1.0")
|
||||
end
|
||||
def test_template_path
|
||||
to_test = { [0,9,5] => "0.9.5",
|
||||
[1,0] => "1.0",
|
||||
"Unknown version" => "1.0",
|
||||
[1,0,1] => "1.0"}
|
||||
|
||||
def test_version_template_1_0_win
|
||||
test_version_template_for("1e4ddc9ac9f7+20080325", "Unknown version", "1.0")
|
||||
to_test.each do |v, template|
|
||||
test_template_path_for(v, template)
|
||||
end
|
||||
|
||||
def test_version_template_1_0_1_win
|
||||
test_version_template_for("1.0.1+20080525", [1,0,1], "1.0")
|
||||
end
|
||||
|
||||
def test_version_template_changeset_id
|
||||
test_version_template_for("1916e629a29d", "Unknown version", "1.0")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def test_version_template_for(hgversion, version, templateversion)
|
||||
Redmine::Scm::Adapters::MercurialAdapter.any_instance.stubs(:hgversion_from_command_line).returns(hgversion)
|
||||
adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH)
|
||||
def test_hgversion_for(hgversion, version)
|
||||
Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion)
|
||||
adapter = Redmine::Scm::Adapters::MercurialAdapter
|
||||
assert_equal version, adapter.hgversion
|
||||
assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{templateversion}.#{TEMPLATE_EXTENSION}", adapter.template_path
|
||||
assert File.exist?(adapter.template_path)
|
||||
end
|
||||
|
||||
def test_template_path_for(version, template)
|
||||
adapter = Redmine::Scm::Adapters::MercurialAdapter
|
||||
assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version)
|
||||
assert File.exist?(adapter.template_path_for(version))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue