comparison app/models/repository/git.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children a1bdbf8a87d5
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
91 changesets.where(:revision => name.to_s).first || 91 changesets.where(:revision => name.to_s).first ||
92 changesets.where('scmid LIKE ?', "#{name}%").first 92 changesets.where('scmid LIKE ?', "#{name}%").first
93 end 93 end
94 end 94 end
95 95
96 def entries(path=nil, identifier=nil) 96 def scm_entries(path=nil, identifier=nil)
97 entries = scm.entries(path, identifier, :report_last_commit => extra_report_last_commit) 97 scm.entries(path, identifier, :report_last_commit => extra_report_last_commit)
98 load_entries_changesets(entries) 98 end
99 entries 99 protected :scm_entries
100 end
101 100
102 # With SCMs that have a sequential commit numbering, 101 # With SCMs that have a sequential commit numbering,
103 # such as Subversion and Mercurial, 102 # such as Subversion and Mercurial,
104 # Redmine is able to be clever and only fetch changesets 103 # Redmine is able to be clever and only fetch changesets
105 # going forward from the most recent one it knows about. 104 # going forward from the most recent one it knows about.
178 # 177 #
179 # After re-pushing branch, "git log" returns revisions which are saved in database. 178 # After re-pushing branch, "git log" returns revisions which are saved in database.
180 # So, Redmine needs to scan revisions and database every time. 179 # So, Redmine needs to scan revisions and database every time.
181 # 180 #
182 # This is replacing the one-after-one queries. 181 # This is replacing the one-after-one queries.
183 # Find all revisions, that are in the database, and then remove them from the revision array. 182 # Find all revisions, that are in the database, and then remove them
183 # from the revision array.
184 # Then later we won't need any conditions for db existence. 184 # Then later we won't need any conditions for db existence.
185 # Query for several revisions at once, and remove them from the revisions array, if they are there. 185 # Query for several revisions at once, and remove them
186 # Do this in chunks, to avoid eventual memory problems (in case of tens of thousands of commits). 186 # from the revisions array, if they are there.
187 # Do this in chunks, to avoid eventual memory problems
188 # (in case of tens of thousands of commits).
187 # If there are no revisions (because the original code's algorithm filtered them), 189 # If there are no revisions (because the original code's algorithm filtered them),
188 # then this part will be stepped over. 190 # then this part will be stepped over.
189 # We make queries, just if there is any revision. 191 # We make queries, just if there is any revision.
190 limit = 100 192 limit = 100
191 offset = 0 193 offset = 0
192 revisions_copy = revisions.clone # revisions will change 194 revisions_copy = revisions.clone # revisions will change
193 while offset < revisions_copy.size 195 while offset < revisions_copy.size
194 scmids = revisions_copy.slice(offset, limit).map{|x| x.scmid} 196 scmids = revisions_copy.slice(offset, limit).map{|x| x.scmid}
195 recent_changesets_slice = changesets.where(:scmid => scmids).all 197 recent_changesets_slice = changesets.where(:scmid => scmids)
196 # Subtract revisions that redmine already knows about 198 # Subtract revisions that redmine already knows about
197 recent_revisions = recent_changesets_slice.map{|c| c.scmid} 199 recent_revisions = recent_changesets_slice.map{|c| c.scmid}
198 revisions.reject!{|r| recent_revisions.include?(r.scmid)} 200 revisions.reject!{|r| recent_revisions.include?(r.scmid)}
199 offset += limit 201 offset += limit
200 end 202 end
201
202 revisions.each do |rev| 203 revisions.each do |rev|
203 transaction do 204 transaction do
204 # There is no search in the db for this revision, because above we ensured, 205 # There is no search in the db for this revision, because above we ensured,
205 # that it's not in the db. 206 # that it's not in the db.
206 save_revision(rev) 207 save_revision(rev)
238 end 239 end
239 240
240 def latest_changesets(path,rev,limit=10) 241 def latest_changesets(path,rev,limit=10)
241 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false) 242 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
242 return [] if revisions.nil? || revisions.empty? 243 return [] if revisions.nil? || revisions.empty?
243
244 changesets.where(:scmid => revisions.map {|c| c.scmid}).all 244 changesets.where(:scmid => revisions.map {|c| c.scmid}).all
245 end 245 end
246 246
247 def clear_extra_info_of_changesets 247 def clear_extra_info_of_changesets
248 return if extra_info.nil? 248 return if extra_info.nil?