##// END OF EJS Templates
scm: code clean up repository model....
Toshi MARUYAMA -
r5527:86d9ea32dbd2
parent child
Show More
@@ -134,7 +134,8 class Repository < ActiveRecord::Base
134 134 # Finds and returns a revision with a number or the beginning of a hash
135 135 def find_changeset_by_name(name)
136 136 return nil if name.blank?
137 changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
137 changesets.find(:first, :conditions => (name.match(/^\d*$/) ?
138 ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%']))
138 139 end
139 140
140 141 def latest_changeset
@@ -155,16 +156,17 class Repository < ActiveRecord::Base
155 156 :limit => limit).collect(&:changeset)
156 157 end
157 158 end
158
159
159 160 def scan_changesets_for_issue_ids
160 161 self.changesets.each(&:scan_comment_for_issue_ids)
161 162 end
162 163
163 164 # Returns an array of committers usernames and associated user_id
164 165 def committers
165 @committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
166 @committers ||= Changeset.connection.select_rows(
167 "SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}")
166 168 end
167
169
168 170 # Maps committers username to a user ids
169 171 def committer_ids=(h)
170 172 if h.is_a?(Hash)
@@ -172,17 +174,19 class Repository < ActiveRecord::Base
172 174 new_user_id = h[committer]
173 175 if new_user_id && (new_user_id.to_i != user_id.to_i)
174 176 new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
175 Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer])
177 Changeset.update_all(
178 "user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }",
179 ["repository_id = ? AND committer = ?", id, committer])
176 180 end
177 181 end
178 @committers = nil
182 @committers = nil
179 183 @found_committer_users = nil
180 184 true
181 185 else
182 186 false
183 187 end
184 188 end
185
189
186 190 # Returns the Redmine User corresponding to the given +committer+
187 191 # It will return nil if the committer is not yet mapped and if no User
188 192 # with the same username or email was found
@@ -190,7 +194,7 class Repository < ActiveRecord::Base
190 194 unless committer.blank?
191 195 @found_committer_users ||= {}
192 196 return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
193
197
194 198 user = nil
195 199 c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
196 200 if c && c.user
@@ -288,7 +292,7 class Repository < ActiveRecord::Base
288 292 root_url.strip!
289 293 true
290 294 end
291
295
292 296 def clear_changesets
293 297 cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
294 298 connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
General Comments 0
You need to be logged in to leave comments. Login now