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