##// 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 # Finds and returns a revision with a number or the beginning of a hash
134 # Finds and returns a revision with a number or the beginning of a hash
135 def find_changeset_by_name(name)
135 def find_changeset_by_name(name)
136 return nil if name.blank?
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 end
139 end
139
140
140 def latest_changeset
141 def latest_changeset
@@ -155,16 +156,17 class Repository < ActiveRecord::Base
155 :limit => limit).collect(&:changeset)
156 :limit => limit).collect(&:changeset)
156 end
157 end
157 end
158 end
158
159
159 def scan_changesets_for_issue_ids
160 def scan_changesets_for_issue_ids
160 self.changesets.each(&:scan_comment_for_issue_ids)
161 self.changesets.each(&:scan_comment_for_issue_ids)
161 end
162 end
162
163
163 # Returns an array of committers usernames and associated user_id
164 # Returns an array of committers usernames and associated user_id
164 def committers
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 end
168 end
167
169
168 # Maps committers username to a user ids
170 # Maps committers username to a user ids
169 def committer_ids=(h)
171 def committer_ids=(h)
170 if h.is_a?(Hash)
172 if h.is_a?(Hash)
@@ -172,17 +174,19 class Repository < ActiveRecord::Base
172 new_user_id = h[committer]
174 new_user_id = h[committer]
173 if new_user_id && (new_user_id.to_i != user_id.to_i)
175 if new_user_id && (new_user_id.to_i != user_id.to_i)
174 new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil)
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 end
180 end
177 end
181 end
178 @committers = nil
182 @committers = nil
179 @found_committer_users = nil
183 @found_committer_users = nil
180 true
184 true
181 else
185 else
182 false
186 false
183 end
187 end
184 end
188 end
185
189
186 # Returns the Redmine User corresponding to the given +committer+
190 # Returns the Redmine User corresponding to the given +committer+
187 # It will return nil if the committer is not yet mapped and if no User
191 # It will return nil if the committer is not yet mapped and if no User
188 # with the same username or email was found
192 # with the same username or email was found
@@ -190,7 +194,7 class Repository < ActiveRecord::Base
190 unless committer.blank?
194 unless committer.blank?
191 @found_committer_users ||= {}
195 @found_committer_users ||= {}
192 return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
196 return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
193
197
194 user = nil
198 user = nil
195 c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
199 c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
196 if c && c.user
200 if c && c.user
@@ -288,7 +292,7 class Repository < ActiveRecord::Base
288 root_url.strip!
292 root_url.strip!
289 true
293 true
290 end
294 end
291
295
292 def clear_changesets
296 def clear_changesets
293 cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
297 cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
294 connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
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