##// END OF EJS Templates
Fixes Repository#clear_changesets....
Jean-Philippe Lang -
r1782:4b9df2eac774
parent child
Show More
@@ -1,139 +1,140
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 belongs_to :project
20 20 has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
21 21 has_many :changes, :through => :changesets
22 22
23 23 # Raw SQL to delete changesets and changes in the database
24 24 # has_many :changesets, :dependent => :destroy is too slow for big repositories
25 25 before_destroy :clear_changesets
26 26
27 27 # Checks if the SCM is enabled when creating a repository
28 28 validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) }
29 29
30 30 # Removes leading and trailing whitespace
31 31 def url=(arg)
32 32 write_attribute(:url, arg ? arg.to_s.strip : nil)
33 33 end
34 34
35 35 # Removes leading and trailing whitespace
36 36 def root_url=(arg)
37 37 write_attribute(:root_url, arg ? arg.to_s.strip : nil)
38 38 end
39 39
40 40 def scm
41 41 @scm ||= self.scm_adapter.new url, root_url, login, password
42 42 update_attribute(:root_url, @scm.root_url) if root_url.blank?
43 43 @scm
44 44 end
45 45
46 46 def scm_name
47 47 self.class.scm_name
48 48 end
49 49
50 50 def supports_cat?
51 51 scm.supports_cat?
52 52 end
53 53
54 54 def supports_annotate?
55 55 scm.supports_annotate?
56 56 end
57 57
58 58 def entry(path=nil, identifier=nil)
59 59 scm.entry(path, identifier)
60 60 end
61 61
62 62 def entries(path=nil, identifier=nil)
63 63 scm.entries(path, identifier)
64 64 end
65 65
66 66 def properties(path, identifier=nil)
67 67 scm.properties(path, identifier)
68 68 end
69 69
70 70 def cat(path, identifier=nil)
71 71 scm.cat(path, identifier)
72 72 end
73 73
74 74 def diff(path, rev, rev_to)
75 75 scm.diff(path, rev, rev_to)
76 76 end
77 77
78 78 # Default behaviour: we search in cached changesets
79 79 def changesets_for_path(path)
80 80 path = "/#{path}" unless path.starts_with?('/')
81 81 Change.find(:all, :include => :changeset,
82 82 :conditions => ["repository_id = ? AND path = ?", id, path],
83 83 :order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset)
84 84 end
85 85
86 86 # Returns a path relative to the url of the repository
87 87 def relative_path(path)
88 88 path
89 89 end
90 90
91 91 def latest_changeset
92 92 @latest_changeset ||= changesets.find(:first)
93 93 end
94 94
95 95 def scan_changesets_for_issue_ids
96 96 self.changesets.each(&:scan_comment_for_issue_ids)
97 97 end
98 98
99 99 # fetch new changesets for all repositories
100 100 # can be called periodically by an external script
101 101 # eg. ruby script/runner "Repository.fetch_changesets"
102 102 def self.fetch_changesets
103 103 find(:all).each(&:fetch_changesets)
104 104 end
105 105
106 106 # scan changeset comments to find related and fixed issues for all repositories
107 107 def self.scan_changesets_for_issue_ids
108 108 find(:all).each(&:scan_changesets_for_issue_ids)
109 109 end
110 110
111 111 def self.scm_name
112 112 'Abstract'
113 113 end
114 114
115 115 def self.available_scm
116 116 subclasses.collect {|klass| [klass.scm_name, klass.name]}
117 117 end
118 118
119 119 def self.factory(klass_name, *args)
120 120 klass = "Repository::#{klass_name}".constantize
121 121 klass.new(*args)
122 122 rescue
123 123 nil
124 124 end
125 125
126 126 private
127 127
128 128 def before_save
129 129 # Strips url and root_url
130 130 url.strip!
131 131 root_url.strip!
132 132 true
133 133 end
134 134
135 135 def clear_changesets
136 136 connection.delete("DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
137 connection.delete("DELETE FROM changesets_issues WHERE changesets_issues.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})")
137 138 connection.delete("DELETE FROM changesets WHERE changesets.repository_id = #{id}")
138 139 end
139 140 end
General Comments 0
You need to be logged in to leave comments. Login now