From 8d5617fc8b68d96f7d2caa318bb29e27b089c733 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Mon, 14 Feb 2011 08:45:34 +0000 Subject: [PATCH] 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 --- app/models/repository.rb | 24 ++++++++++++++++++++++-- app/models/repository/bazaar.rb | 6 +++--- app/models/repository/cvs.rb | 6 +++--- app/models/repository/darcs.rb | 6 +++--- app/models/repository/filesystem.rb | 6 +++--- app/models/repository/git.rb | 4 ++-- app/models/repository/mercurial.rb | 2 +- app/models/repository/subversion.rb | 4 ++-- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 3d463b82..1fbcf5f5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/models/repository/bazaar.rb b/app/models/repository/bazaar.rb index ec953bd4..9d7977e7 100644 --- a/app/models/repository/bazaar.rb +++ b/app/models/repository/bazaar.rb @@ -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 diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index dbbb4694..c0cac5cd 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -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) diff --git a/app/models/repository/darcs.rb b/app/models/repository/darcs.rb index 43fb0294..dc3f0cee 100644 --- a/app/models/repository/darcs.rb +++ b/app/models/repository/darcs.rb @@ -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) diff --git a/app/models/repository/filesystem.rb b/app/models/repository/filesystem.rb index da096cc0..4be6b528 100644 --- a/app/models/repository/filesystem.rb +++ b/app/models/repository/filesystem.rb @@ -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 diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index 9349f3c1..26cb84db 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -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 diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index 102c6dda..557b9a4d 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -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 diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb index 091d1413..05936929 100644 --- a/app/models/repository/subversion.rb +++ b/app/models/repository/subversion.rb @@ -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