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) write_attribute(:root_url, arg ? arg.to_s.strip : nil)
end end
def scm_adapter
self.class.scm_adapter_class
end
def scm def scm
@scm ||= self.scm_adapter.new url, root_url, login, password @scm ||= self.scm_adapter.new url, root_url, login, password
update_attribute(:root_url, @scm.root_url) if root_url.blank? update_attribute(:root_url, @scm.root_url) if root_url.blank?
@ -46,7 +50,7 @@ class Repository < ActiveRecord::Base
def scm_name def scm_name
self.class.scm_name self.class.scm_name
end end
def supports_cat? def supports_cat?
scm.supports_cat? scm.supports_cat?
end end
@ -204,7 +208,23 @@ class Repository < ActiveRecord::Base
rescue rescue
nil nil
end 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 private
def before_save def before_save

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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