##// END OF EJS Templates
Transaction for each imported subversion changeset....
Jean-Philippe Lang -
r2495:7bd4590cd614
parent child
Show More
@@ -1,89 +1,89
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'redmine/scm/adapters/subversion_adapter'
18 require 'redmine/scm/adapters/subversion_adapter'
19
19
20 class Repository::Subversion < Repository
20 class Repository::Subversion < Repository
21 attr_protected :root_url
21 attr_protected :root_url
22 validates_presence_of :url
22 validates_presence_of :url
23 validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i
23 validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i
24
24
25 def scm_adapter
25 def scm_adapter
26 Redmine::Scm::Adapters::SubversionAdapter
26 Redmine::Scm::Adapters::SubversionAdapter
27 end
27 end
28
28
29 def self.scm_name
29 def self.scm_name
30 'Subversion'
30 'Subversion'
31 end
31 end
32
32
33 def changesets_for_path(path, options={})
33 def changesets_for_path(path, options={})
34 revisions = scm.revisions(path, nil, nil, :limit => options[:limit])
34 revisions = scm.revisions(path, nil, nil, :limit => options[:limit])
35 revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
35 revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
36 end
36 end
37
37
38 # Returns a path relative to the url of the repository
38 # Returns a path relative to the url of the repository
39 def relative_path(path)
39 def relative_path(path)
40 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
40 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
41 end
41 end
42
42
43 def fetch_changesets
43 def fetch_changesets
44 scm_info = scm.info
44 scm_info = scm.info
45 if scm_info
45 if scm_info
46 # latest revision found in database
46 # latest revision found in database
47 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
47 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
48 # latest revision in the repository
48 # latest revision in the repository
49 scm_revision = scm_info.lastrev.identifier.to_i
49 scm_revision = scm_info.lastrev.identifier.to_i
50 if db_revision < scm_revision
50 if db_revision < scm_revision
51 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
51 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
52 identifier_from = db_revision + 1
52 identifier_from = db_revision + 1
53 while (identifier_from <= scm_revision)
53 while (identifier_from <= scm_revision)
54 # loads changesets by batches of 200
54 # loads changesets by batches of 200
55 identifier_to = [identifier_from + 199, scm_revision].min
55 identifier_to = [identifier_from + 199, scm_revision].min
56 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
56 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
57 transaction do
57 revisions.reverse_each do |revision|
58 revisions.reverse_each do |revision|
58 transaction do
59 changeset = Changeset.create(:repository => self,
59 changeset = Changeset.create(:repository => self,
60 :revision => revision.identifier,
60 :revision => revision.identifier,
61 :committer => revision.author,
61 :committer => revision.author,
62 :committed_on => revision.time,
62 :committed_on => revision.time,
63 :comments => revision.message)
63 :comments => revision.message)
64
64
65 revision.paths.each do |change|
65 revision.paths.each do |change|
66 Change.create(:changeset => changeset,
66 Change.create(:changeset => changeset,
67 :action => change[:action],
67 :action => change[:action],
68 :path => change[:path],
68 :path => change[:path],
69 :from_path => change[:from_path],
69 :from_path => change[:from_path],
70 :from_revision => change[:from_revision])
70 :from_revision => change[:from_revision])
71 end
71 end unless changeset.new_record?
72 end
72 end
73 end unless revisions.nil?
73 end unless revisions.nil?
74 identifier_from = identifier_to + 1
74 identifier_from = identifier_to + 1
75 end
75 end
76 end
76 end
77 end
77 end
78 end
78 end
79
79
80 private
80 private
81
81
82 # Returns the relative url of the repository
82 # Returns the relative url of the repository
83 # Eg: root_url = file:///var/svn/foo
83 # Eg: root_url = file:///var/svn/foo
84 # url = file:///var/svn/foo/bar
84 # url = file:///var/svn/foo/bar
85 # => returns /bar
85 # => returns /bar
86 def relative_url
86 def relative_url
87 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '')
87 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '')
88 end
88 end
89 end
89 end
General Comments 0
You need to be logged in to leave comments. Login now