##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r9625:888d2841367a
parent child
Show More
@@ -1,109 +1,114
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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(\+[^\s:\/\\]+)?|file):\/\/.+/i
23 validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
24
24
25 def self.scm_adapter_class
25 def self.scm_adapter_class
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 supports_directory_revisions?
33 def supports_directory_revisions?
34 true
34 true
35 end
35 end
36
36
37 def repo_log_encoding
37 def repo_log_encoding
38 'UTF-8'
38 'UTF-8'
39 end
39 end
40
40
41 def latest_changesets(path, rev, limit=10)
41 def latest_changesets(path, rev, limit=10)
42 revisions = scm.revisions(path, rev, nil, :limit => limit)
42 revisions = scm.revisions(path, rev, nil, :limit => limit)
43 revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
43 if revisions
44 identifiers = revisions.collect(&:identifier).compact
45 changesets.where(:revision => identifiers).reorder("committed_on DESC").includes(:repository, :user).all
46 else
47 []
48 end
44 end
49 end
45
50
46 # Returns a path relative to the url of the repository
51 # Returns a path relative to the url of the repository
47 def relative_path(path)
52 def relative_path(path)
48 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
53 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
49 end
54 end
50
55
51 def fetch_changesets
56 def fetch_changesets
52 scm_info = scm.info
57 scm_info = scm.info
53 if scm_info
58 if scm_info
54 # latest revision found in database
59 # latest revision found in database
55 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
60 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
56 # latest revision in the repository
61 # latest revision in the repository
57 scm_revision = scm_info.lastrev.identifier.to_i
62 scm_revision = scm_info.lastrev.identifier.to_i
58 if db_revision < scm_revision
63 if db_revision < scm_revision
59 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
64 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
60 identifier_from = db_revision + 1
65 identifier_from = db_revision + 1
61 while (identifier_from <= scm_revision)
66 while (identifier_from <= scm_revision)
62 # loads changesets by batches of 200
67 # loads changesets by batches of 200
63 identifier_to = [identifier_from + 199, scm_revision].min
68 identifier_to = [identifier_from + 199, scm_revision].min
64 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
69 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
65 revisions.reverse_each do |revision|
70 revisions.reverse_each do |revision|
66 transaction do
71 transaction do
67 changeset = Changeset.create(:repository => self,
72 changeset = Changeset.create(:repository => self,
68 :revision => revision.identifier,
73 :revision => revision.identifier,
69 :committer => revision.author,
74 :committer => revision.author,
70 :committed_on => revision.time,
75 :committed_on => revision.time,
71 :comments => revision.message)
76 :comments => revision.message)
72
77
73 revision.paths.each do |change|
78 revision.paths.each do |change|
74 changeset.create_change(change)
79 changeset.create_change(change)
75 end unless changeset.new_record?
80 end unless changeset.new_record?
76 end
81 end
77 end unless revisions.nil?
82 end unless revisions.nil?
78 identifier_from = identifier_to + 1
83 identifier_from = identifier_to + 1
79 end
84 end
80 end
85 end
81 end
86 end
82 end
87 end
83
88
84 protected
89 protected
85
90
86 def load_entries_changesets(entries)
91 def load_entries_changesets(entries)
87 entries_with_identifier = entries.select {|entry| entry.lastrev && entry.lastrev.identifier.present?}
92 entries_with_identifier = entries.select {|entry| entry.lastrev && entry.lastrev.identifier.present?}
88 identifiers = entries_with_identifier.map {|entry| entry.lastrev.identifier}.compact.uniq
93 identifiers = entries_with_identifier.map {|entry| entry.lastrev.identifier}.compact.uniq
89
94
90 if identifiers.any?
95 if identifiers.any?
91 changesets_by_identifier = changesets.where(:revision => identifiers).includes(:user, :repository).all.group_by(&:revision)
96 changesets_by_identifier = changesets.where(:revision => identifiers).includes(:user, :repository).all.group_by(&:revision)
92 entries_with_identifier.each do |entry|
97 entries_with_identifier.each do |entry|
93 if m = changesets_by_identifier[entry.lastrev.identifier]
98 if m = changesets_by_identifier[entry.lastrev.identifier]
94 entry.changeset = m.first
99 entry.changeset = m.first
95 end
100 end
96 end
101 end
97 end
102 end
98 end
103 end
99
104
100 private
105 private
101
106
102 # Returns the relative url of the repository
107 # Returns the relative url of the repository
103 # Eg: root_url = file:///var/svn/foo
108 # Eg: root_url = file:///var/svn/foo
104 # url = file:///var/svn/foo/bar
109 # url = file:///var/svn/foo/bar
105 # => returns /bar
110 # => returns /bar
106 def relative_url
111 def relative_url
107 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url || scm.root_url)}", Regexp::IGNORECASE), '')
112 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url || scm.root_url)}", Regexp::IGNORECASE), '')
108 end
113 end
109 end
114 end
General Comments 0
You need to be logged in to leave comments. Login now