@@ -1,182 +1,182 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 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 'iconv' |
|
19 | 19 | |
|
20 | 20 | module RepositoriesHelper |
|
21 | 21 | def format_revision(txt) |
|
22 | 22 | txt.to_s[0,8] |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def truncate_at_line_break(text, length = 255) |
|
26 | 26 | if text |
|
27 | 27 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
|
28 | 28 | end |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def render_properties(properties) |
|
32 | 32 | unless properties.nil? || properties.empty? |
|
33 | 33 | content = '' |
|
34 | 34 | properties.keys.sort.each do |property| |
|
35 | 35 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
|
36 | 36 | end |
|
37 | 37 | content_tag('ul', content, :class => 'properties') |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def render_changeset_changes |
|
42 | 42 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
|
43 | 43 | case change.action |
|
44 | 44 | when 'A' |
|
45 | 45 | # Detects moved/copied files |
|
46 | 46 | if !change.from_path.blank? |
|
47 | 47 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
|
48 | 48 | end |
|
49 | 49 | change |
|
50 | 50 | when 'D' |
|
51 | 51 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
|
52 | 52 | else |
|
53 | 53 | change |
|
54 | 54 | end |
|
55 | 55 | end.compact |
|
56 | 56 | |
|
57 | 57 | tree = { } |
|
58 | 58 | changes.each do |change| |
|
59 | 59 | p = tree |
|
60 | 60 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
|
61 | 61 | dirs.each do |dir| |
|
62 | 62 | p[:s] ||= {} |
|
63 | 63 | p = p[:s] |
|
64 | 64 | p[dir] ||= {} |
|
65 | 65 | p = p[dir] |
|
66 | 66 | end |
|
67 | 67 | p[:c] = change |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | render_changes_tree(tree[:s]) |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def render_changes_tree(tree) |
|
74 | 74 | return '' if tree.nil? |
|
75 | 75 | |
|
76 | 76 | output = '' |
|
77 | 77 | output << '<ul>' |
|
78 | 78 | tree.keys.sort.each do |file| |
|
79 | 79 | s = !tree[file][:s].nil? |
|
80 | 80 | c = tree[file][:c] |
|
81 | 81 | |
|
82 | 82 | style = 'change' |
|
83 | 83 | style << ' folder' if s |
|
84 | 84 | style << " change-#{c.action}" if c |
|
85 | 85 | |
|
86 | 86 | text = h(file) |
|
87 | 87 | unless c.nil? |
|
88 | 88 | path_param = to_path_param(@repository.relative_path(c.path)) |
|
89 | 89 | text = link_to(text, :controller => 'repositories', |
|
90 | 90 | :action => 'entry', |
|
91 | 91 | :id => @project, |
|
92 | 92 | :path => path_param, |
|
93 | 93 | :rev => @changeset.revision) unless s || c.action == 'D' |
|
94 | 94 | text << " - #{c.revision}" unless c.revision.blank? |
|
95 | 95 | text << ' (' + link_to('diff', :controller => 'repositories', |
|
96 | 96 | :action => 'diff', |
|
97 | 97 | :id => @project, |
|
98 | 98 | :path => path_param, |
|
99 | 99 | :rev => @changeset.revision) + ') ' if c.action == 'M' |
|
100 | 100 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
|
101 | 101 | end |
|
102 | 102 | output << "<li class='#{style}'>#{text}</li>" |
|
103 | 103 | output << render_changes_tree(tree[file][:s]) if s |
|
104 | 104 | end |
|
105 | 105 | output << '</ul>' |
|
106 | 106 | output |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def to_utf8(str) |
|
110 | 110 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
111 | 111 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
112 | 112 | @encodings.each do |encoding| |
|
113 | 113 | begin |
|
114 | 114 | return Iconv.conv('UTF-8', encoding, str) |
|
115 | 115 | rescue Iconv::Failure |
|
116 | 116 | # do nothing here and try the next encoding |
|
117 | 117 | end |
|
118 | 118 | end |
|
119 | 119 | str |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def repository_field_tags(form, repository) |
|
123 | 123 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
124 | 124 | send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def scm_select_tag(repository) |
|
128 | 128 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
|
129 | 129 | REDMINE_SUPPORTED_SCM.each do |scm| |
|
130 | 130 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | select_tag('repository_scm', |
|
134 | 134 | options_for_select(scm_options, repository.class.name.demodulize), |
|
135 | 135 | :disabled => (repository && !repository.new_record?), |
|
136 | 136 | :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") |
|
137 | 137 | ) |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def with_leading_slash(path) |
|
141 | 141 | path.to_s.starts_with?('/') ? path : "/#{path}" |
|
142 | 142 | end |
|
143 | 143 | |
|
144 | 144 | def without_leading_slash(path) |
|
145 | 145 | path.gsub(%r{^/+}, '') |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | def subversion_field_tags(form, repository) |
|
149 | 149 | content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + |
|
150 |
'<br />(http://, https://, svn://, |
|
|
150 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | |
|
151 | 151 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
152 | 152 | content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', |
|
153 | 153 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
154 | 154 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
155 | 155 | :onchange => "this.name='repository[password]';")) |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | def darcs_field_tags(form, repository) |
|
159 | 159 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def mercurial_field_tags(form, repository) |
|
163 | 163 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def git_field_tags(form, repository) |
|
167 | 167 | content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def cvs_field_tags(form, repository) |
|
171 | 171 | content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + |
|
172 | 172 | content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | def bazaar_field_tags(form, repository) |
|
176 | 176 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
|
177 | 177 | end |
|
178 | 178 | |
|
179 | 179 | def filesystem_field_tags(form, repository) |
|
180 | 180 | content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
|
181 | 181 | end |
|
182 | 182 | end |
@@ -1,89 +1,89 | |||
|
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 | 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 |
validates_format_of :url, :with => /^(http|https|svn |
|
|
23 | validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i | |
|
24 | 24 | |
|
25 | 25 | def scm_adapter |
|
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 changesets_for_path(path, options={}) |
|
34 | 34 | revisions = scm.revisions(path, nil, nil, :limit => options[:limit]) |
|
35 | 35 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : [] |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | # Returns a path relative to the url of the repository |
|
39 | 39 | def relative_path(path) |
|
40 | 40 | path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '') |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def fetch_changesets |
|
44 | 44 | scm_info = scm.info |
|
45 | 45 | if scm_info |
|
46 | 46 | # latest revision found in database |
|
47 | 47 | db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 |
|
48 | 48 | # latest revision in the repository |
|
49 | 49 | scm_revision = scm_info.lastrev.identifier.to_i |
|
50 | 50 | if db_revision < scm_revision |
|
51 | 51 | logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? |
|
52 | 52 | identifier_from = db_revision + 1 |
|
53 | 53 | while (identifier_from <= scm_revision) |
|
54 | 54 | # loads changesets by batches of 200 |
|
55 | 55 | identifier_to = [identifier_from + 199, scm_revision].min |
|
56 | 56 | revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true) |
|
57 | 57 | revisions.reverse_each do |revision| |
|
58 | 58 | transaction do |
|
59 | 59 | changeset = Changeset.create(:repository => self, |
|
60 | 60 | :revision => revision.identifier, |
|
61 | 61 | :committer => revision.author, |
|
62 | 62 | :committed_on => revision.time, |
|
63 | 63 | :comments => revision.message) |
|
64 | 64 | |
|
65 | 65 | revision.paths.each do |change| |
|
66 | 66 | Change.create(:changeset => changeset, |
|
67 | 67 | :action => change[:action], |
|
68 | 68 | :path => change[:path], |
|
69 | 69 | :from_path => change[:from_path], |
|
70 | 70 | :from_revision => change[:from_revision]) |
|
71 | 71 | end unless changeset.new_record? |
|
72 | 72 | end |
|
73 | 73 | end unless revisions.nil? |
|
74 | 74 | identifier_from = identifier_to + 1 |
|
75 | 75 | end |
|
76 | 76 | end |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | private |
|
81 | 81 | |
|
82 | 82 | # Returns the relative url of the repository |
|
83 | 83 | # Eg: root_url = file:///var/svn/foo |
|
84 | 84 | # url = file:///var/svn/foo/bar |
|
85 | 85 | # => returns /bar |
|
86 | 86 | def relative_url |
|
87 | 87 | @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '') |
|
88 | 88 | end |
|
89 | 89 | end |
General Comments 0
You need to be logged in to leave comments.
Login now