##// END OF EJS Templates
fixed bug 9537 fetch_changesets broken...
Jean-Philippe Lang -
r379:1f7863e32391
parent child
Show More
@@ -1,96 +1,88
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, :dependent => :destroy, :order => 'revision DESC'
21 21 has_many :changes, :through => :changesets
22 22 has_one :latest_changeset, :class_name => 'Changeset', :foreign_key => :repository_id, :order => 'revision DESC'
23 23
24 24 attr_protected :root_url
25 25
26 26 validates_presence_of :url
27 27 validates_format_of :url, :with => /^(http|https|svn|file):\/\/.+/i
28 28
29 29 def scm
30 30 @scm ||= SvnRepos::Base.new url, root_url, login, password
31 31 update_attribute(:root_url, @scm.root_url) if root_url.blank?
32 32 @scm
33 33 end
34 34
35 35 def url=(str)
36 36 super if root_url.blank?
37 37 end
38 38
39 39 def changesets_with_path(path="")
40 40 path = "/#{path}%"
41 41 path = url.gsub(/^#{root_url}/, '') + path if root_url && root_url != url
42 42 path.squeeze!("/")
43 43 Changeset.with_scope(:find => { :include => :changes, :conditions => ["#{Change.table_name}.path LIKE ?", path] }) do
44 44 yield
45 45 end
46 46 end
47 47
48 def changesets_for_path(path="")
49 path = "/#{path}%"
50 path = url.gsub(/^#{root_url}/, '') + path if root_url && root_url != url
51 path.squeeze!("/")
52 changesets.find(:all, :include => :changes,
53 :conditions => ["#{Change.table_name}.path LIKE ?", path])
54 end
55
56 48 def fetch_changesets
57 49 scm_info = scm.info
58 50 if scm_info
59 51 lastrev_identifier = scm_info.lastrev.identifier.to_i
60 52 if latest_changeset.nil? || latest_changeset.revision < lastrev_identifier
61 53 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
62 54 identifier_from = latest_changeset ? latest_changeset.revision + 1 : 1
63 55 while (identifier_from <= lastrev_identifier)
64 56 # loads changesets by batches of 200
65 57 identifier_to = [identifier_from + 199, lastrev_identifier].min
66 58 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
67 59 transaction do
68 60 revisions.reverse_each do |revision|
69 61 changeset = Changeset.create(:repository => self,
70 62 :revision => revision.identifier,
71 63 :committer => revision.author,
72 64 :committed_on => revision.time,
73 65 :comment => revision.message)
74 66
75 67 revision.paths.each do |change|
76 68 Change.create(:changeset => changeset,
77 69 :action => change[:action],
78 70 :path => change[:path],
79 71 :from_path => change[:from_path],
80 72 :from_revision => change[:from_revision])
81 73 end
82 74 end
83 end
75 end unless revisions.nil?
84 76 identifier_from = identifier_to + 1
85 77 end
86 78 end
87 79 end
88 80 end
89 81
90 82 # fetch new changesets for all repositories
91 83 # can be called periodically by an external script
92 84 # eg. ruby script/runner "Repository.fetch_changesets"
93 85 def self.fetch_changesets
94 86 find(:all).each(&:fetch_changesets)
95 87 end
96 88 end
General Comments 0
You need to be logged in to leave comments. Login now