scm: add scm command and version methods at repository models (#4273).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4822 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-02-14 08:45:34 +00:00
parent 8b98c05879
commit cc4e8fe0d6
8 changed files with 39 additions and 19 deletions

View File

@ -37,6 +37,10 @@ class Repository < ActiveRecord::Base
write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end
def scm_adapter
self.class.scm_adapter_class
end
def scm
@scm ||= self.scm_adapter.new url, root_url, login, password
update_attribute(:root_url, @scm.root_url) if root_url.blank?
@ -46,7 +50,7 @@ class Repository < ActiveRecord::Base
def scm_name
self.class.scm_name
end
def supports_cat?
scm.supports_cat?
end
@ -204,7 +208,23 @@ class Repository < ActiveRecord::Base
rescue
nil
end
def self.scm_adapter_class
nil
end
def self.scm_command
self.scm_adapter_class.nil? ? "" : self.scm_adapter_class.client_command
end
def self.scm_version_string
self.scm_adapter_class.nil? ? "" : self.scm_adapter_class.client_version_string
end
def self.scm_available
self.scm_adapter_class.nil? ? false : self.scm_adapter_class.client_available
end
private
def before_save

View File

@ -21,14 +21,14 @@ class Repository::Bazaar < Repository
attr_protected :root_url
validates_presence_of :url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::BazaarAdapter
end
def self.scm_name
'Bazaar'
end
def entries(path=nil, identifier=nil)
entries = scm.entries(path, identifier)
if entries

View File

@ -21,14 +21,14 @@ require 'digest/sha1'
class Repository::Cvs < Repository
validates_presence_of :url, :root_url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::CvsAdapter
end
def self.scm_name
'CVS'
end
def entry(path=nil, identifier=nil)
rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
scm.entry(path, rev.nil? ? nil : rev.committed_on)

View File

@ -20,14 +20,14 @@ require 'redmine/scm/adapters/darcs_adapter'
class Repository::Darcs < Repository
validates_presence_of :url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::DarcsAdapter
end
def self.scm_name
'Darcs'
end
def entry(path=nil, identifier=nil)
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
scm.entry(path, patch.nil? ? nil : patch.scmid)

View File

@ -24,14 +24,14 @@ class Repository::Filesystem < Repository
attr_protected :root_url
validates_presence_of :url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::FilesystemAdapter
end
def self.scm_name
'Filesystem'
end
def entries(path=nil, identifier=nil)
scm.entries(path, identifier)
end

View File

@ -21,10 +21,10 @@ class Repository::Git < Repository
attr_protected :root_url
validates_presence_of :url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::GitAdapter
end
def self.scm_name
'Git'
end

View File

@ -24,7 +24,7 @@ class Repository::Mercurial < Repository
attr_protected :root_url
validates_presence_of :url
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::MercurialAdapter
end

View File

@ -22,10 +22,10 @@ class Repository::Subversion < Repository
validates_presence_of :url
validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
def scm_adapter
def self.scm_adapter_class
Redmine::Scm::Adapters::SubversionAdapter
end
def self.scm_name
'Subversion'
end