diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-15 18:19:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-15 18:19:19 +0000 |
commit | 1bd5e58c847816ae5751ee0026e55597d1541dd4 (patch) | |
tree | b5c1be1f966f8b08986978713882856d014e363d /app/models/repository.rb | |
parent | d996cc0584901e7f44171093b170f882978124f7 (diff) | |
download | redmine-1bd5e58c847816ae5751ee0026e55597d1541dd4.tar.gz redmine-1bd5e58c847816ae5751ee0026e55597d1541dd4.zip |
Adds support for multiple repositories per project (#779).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8650 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index c231a8724..aad078c7d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -26,11 +26,19 @@ class Repository < ActiveRecord::Base serialize :extra_info + before_save :check_default + # Raw SQL to delete changesets and changes in the database # has_many :changesets, :dependent => :destroy is too slow for big repositories before_destroy :clear_changesets validates_length_of :password, :maximum => 255, :allow_nil => true + validates_length_of :identifier, :maximum => 255, :allow_blank => true + validates_presence_of :identifier, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } + validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true + validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) + # donwcase letters, digits, dashes but not digits only + validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :allow_blank => true # Checks if the SCM is enabled when creating a repository validate :repo_create_validation, :on => :create @@ -65,7 +73,9 @@ class Repository < ActiveRecord::Base end send :attributes_without_extra_info=, p, guard_protected_attributes - merge_extra_info(p_extra) + if p_extra.keys.any? + merge_extra_info(p_extra) + end end # Removes leading and trailing whitespace @@ -101,6 +111,44 @@ class Repository < ActiveRecord::Base self.class.scm_name end + def name + if is_default? + l(:field_repository_is_default) + elsif identifier.present? + identifier + else + scm_name + end + end + + def identifier_param + if is_default? + nil + elsif identifier.present? + identifier + else + id.to_s + end + end + + def <=>(repository) + if is_default? + -1 + elsif repository.is_default? + 1 + else + identifier <=> repository.identifier + end + end + + def self.find_by_identifier_param(param) + if param.to_s =~ /^\d+$/ + find_by_id(param) + else + find_by_identifier(param) + end + end + def merge_extra_info(arg) h = extra_info || {} return h if arg.nil? @@ -269,10 +317,10 @@ class Repository < ActiveRecord::Base # Can be called periodically by an external script # eg. ruby script/runner "Repository.fetch_changesets" def self.fetch_changesets - Project.active.has_module(:repository).find(:all, :include => :repository).each do |project| - if project.repository + Project.active.has_module(:repository).all.each do |project| + project.repositories.each do |repository| begin - project.repository.fetch_changesets + repository.fetch_changesets rescue Redmine::Scm::Adapters::CommandFailed => e logger.error "scm: error during fetching changesets: #{e.message}" end @@ -334,6 +382,21 @@ class Repository < ActiveRecord::Base ret end + def set_as_default? + new_record? && project && !Repository.first(:conditions => {:project_id => project.id}) + end + + protected + + def check_default + if !is_default? && set_as_default? + self.is_default = true + end + if is_default? && is_default_changed? + Repository.update_all(["is_default = ?", false], ["project_id = ?", project_id]) + end + end + private def clear_changesets |