##// END OF EJS Templates
scm: code clean up repository model....
Toshi MARUYAMA -
r5533:fbdbdf96fe91
parent child
Show More
@@ -1,31 +1,31
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 #
8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 #
13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Repository < ActiveRecord::Base
19 19 include Redmine::Ciphering
20
20
21 21 belongs_to :project
22 22 has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
23 23 has_many :changes, :through => :changesets
24
24
25 25 # Raw SQL to delete changesets and changes in the database
26 26 # has_many :changesets, :dependent => :destroy is too slow for big repositories
27 27 before_destroy :clear_changesets
28
28
29 29 validates_length_of :password, :maximum => 255, :allow_nil => true
30 30 # Checks if the SCM is enabled when creating a repository
31 31 validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
@@ -47,11 +47,11 class Repository < ActiveRecord::Base
47 47 def root_url=(arg)
48 48 write_attribute(:root_url, arg ? arg.to_s.strip : nil)
49 49 end
50
50
51 51 def password
52 52 read_ciphered_attribute(:password)
53 53 end
54
54
55 55 def password=(arg)
56 56 write_ciphered_attribute(:password, arg)
57 57 end
@@ -82,15 +82,15 class Repository < ActiveRecord::Base
82 82 def supports_all_revisions?
83 83 true
84 84 end
85
85
86 86 def supports_directory_revisions?
87 87 false
88 88 end
89
89
90 90 def entry(path=nil, identifier=nil)
91 91 scm.entry(path, identifier)
92 92 end
93
93
94 94 def entries(path=nil, identifier=nil)
95 95 scm.entries(path, identifier)
96 96 end
@@ -146,14 +146,19 class Repository < ActiveRecord::Base
146 146 # Default behaviour is to search in cached changesets
147 147 def latest_changesets(path, rev, limit=10)
148 148 if path.blank?
149 changesets.find(:all, :include => :user,
150 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
151 :limit => limit)
149 changesets.find(
150 :all,
151 :include => :user,
152 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
153 :limit => limit)
152 154 else
153 changes.find(:all, :include => {:changeset => :user},
154 :conditions => ["path = ?", path.with_leading_slash],
155 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
156 :limit => limit).collect(&:changeset)
155 changes.find(
156 :all,
157 :include => {:changeset => :user},
158 :conditions => ["path = ?", path.with_leading_slash],
159 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
160 :limit => limit
161 ).collect(&:changeset)
157 162 end
158 163 end
159 164
@@ -238,7 +243,7 class Repository < ActiveRecord::Base
238 243 def self.scm_name
239 244 'Abstract'
240 245 end
241
246
242 247 def self.available_scm
243 248 subclasses.collect {|klass| [klass.scm_name, klass.name]}
244 249 end
@@ -277,7 +282,7 class Repository < ActiveRecord::Base
277 282 def self.scm_available
278 283 ret = false
279 284 begin
280 ret = self.scm_adapter_class.client_available if self.scm_adapter_class
285 ret = self.scm_adapter_class.client_available if self.scm_adapter_class
281 286 rescue Redmine::Scm::Adapters::CommandFailed => e
282 287 logger.error "scm: error during get scm available: #{e.message}"
283 288 end
General Comments 0
You need to be logged in to leave comments. Login now