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