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
This commit is contained in:
1 parent
d996cc0584
commit
1bd5e58c84
32 files changed
+384
-78
No files matched your search
@@ -46,7 +46,8 @@ class Project < ActiveRecord::Base
|
||||
has_many :news, :dependent => :destroy, :include => :author
|
||||
has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
|
||||
has_many :boards, :dependent => :destroy, :order => "position ASC"
|
||||
has_one :repository, :dependent => :destroy
|
||||
has_one :repository, :conditions => ["is_default = ?", true]
|
||||
has_many :repositories, :dependent => :destroy
|
||||
has_many :changesets, :through => :repository
|
||||
has_one :wiki, :dependent => :destroy
|
||||
# Custom field for the project issues
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user