@@ -1,256 +1,260 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 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 'iconv' |
|
18 | require 'iconv' | |
19 |
|
19 | |||
20 | module RepositoriesHelper |
|
20 | module RepositoriesHelper | |
21 | def format_revision(revision) |
|
21 | def format_revision(revision) | |
22 | if revision.respond_to? :format_identifier |
|
22 | if revision.respond_to? :format_identifier | |
23 | revision.format_identifier |
|
23 | revision.format_identifier | |
24 | else |
|
24 | else | |
25 | revision.to_s |
|
25 | revision.to_s | |
26 | end |
|
26 | end | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def truncate_at_line_break(text, length = 255) |
|
29 | def truncate_at_line_break(text, length = 255) | |
30 | if text |
|
30 | if text | |
31 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
|
31 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def render_properties(properties) |
|
35 | def render_properties(properties) | |
36 | unless properties.nil? || properties.empty? |
|
36 | unless properties.nil? || properties.empty? | |
37 | content = '' |
|
37 | content = '' | |
38 | properties.keys.sort.each do |property| |
|
38 | properties.keys.sort.each do |property| | |
39 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
|
39 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") | |
40 | end |
|
40 | end | |
41 | content_tag('ul', content, :class => 'properties') |
|
41 | content_tag('ul', content, :class => 'properties') | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def render_changeset_changes |
|
45 | def render_changeset_changes | |
46 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
|
46 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| | |
47 | case change.action |
|
47 | case change.action | |
48 | when 'A' |
|
48 | when 'A' | |
49 | # Detects moved/copied files |
|
49 | # Detects moved/copied files | |
50 | if !change.from_path.blank? |
|
50 | if !change.from_path.blank? | |
51 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
|
51 | change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' | |
52 | end |
|
52 | end | |
53 | change |
|
53 | change | |
54 | when 'D' |
|
54 | when 'D' | |
55 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
|
55 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change | |
56 | else |
|
56 | else | |
57 | change |
|
57 | change | |
58 | end |
|
58 | end | |
59 | end.compact |
|
59 | end.compact | |
60 |
|
60 | |||
61 | tree = { } |
|
61 | tree = { } | |
62 | changes.each do |change| |
|
62 | changes.each do |change| | |
63 | p = tree |
|
63 | p = tree | |
64 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
|
64 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} | |
65 | path = '' |
|
65 | path = '' | |
66 | dirs.each do |dir| |
|
66 | dirs.each do |dir| | |
67 | path += '/' + dir |
|
67 | path += '/' + dir | |
68 | p[:s] ||= {} |
|
68 | p[:s] ||= {} | |
69 | p = p[:s] |
|
69 | p = p[:s] | |
70 | p[path] ||= {} |
|
70 | p[path] ||= {} | |
71 | p = p[path] |
|
71 | p = p[path] | |
72 | end |
|
72 | end | |
73 | p[:c] = change |
|
73 | p[:c] = change | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | render_changes_tree(tree[:s]) |
|
76 | render_changes_tree(tree[:s]) | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def render_changes_tree(tree) |
|
79 | def render_changes_tree(tree) | |
80 | return '' if tree.nil? |
|
80 | return '' if tree.nil? | |
81 |
|
81 | |||
82 | output = '' |
|
82 | output = '' | |
83 | output << '<ul>' |
|
83 | output << '<ul>' | |
84 | tree.keys.sort.each do |file| |
|
84 | tree.keys.sort.each do |file| | |
85 | style = 'change' |
|
85 | style = 'change' | |
86 | text = File.basename(h(file)) |
|
86 | text = File.basename(h(file)) | |
87 | if s = tree[file][:s] |
|
87 | if s = tree[file][:s] | |
88 | style << ' folder' |
|
88 | style << ' folder' | |
89 | path_param = to_path_param(@repository.relative_path(file)) |
|
89 | path_param = to_path_param(@repository.relative_path(file)) | |
90 | text = link_to(text, :controller => 'repositories', |
|
90 | text = link_to(text, :controller => 'repositories', | |
91 | :action => 'show', |
|
91 | :action => 'show', | |
92 | :id => @project, |
|
92 | :id => @project, | |
93 | :path => path_param, |
|
93 | :path => path_param, | |
94 | :rev => @changeset.identifier) |
|
94 | :rev => @changeset.identifier) | |
95 | output << "<li class='#{style}'>#{text}</li>" |
|
95 | output << "<li class='#{style}'>#{text}</li>" | |
96 | output << render_changes_tree(s) |
|
96 | output << render_changes_tree(s) | |
97 | elsif c = tree[file][:c] |
|
97 | elsif c = tree[file][:c] | |
98 | style << " change-#{c.action}" |
|
98 | style << " change-#{c.action}" | |
99 | path_param = to_path_param(@repository.relative_path(c.path)) |
|
99 | path_param = to_path_param(@repository.relative_path(c.path)) | |
100 | text = link_to(text, :controller => 'repositories', |
|
100 | text = link_to(text, :controller => 'repositories', | |
101 | :action => 'entry', |
|
101 | :action => 'entry', | |
102 | :id => @project, |
|
102 | :id => @project, | |
103 | :path => path_param, |
|
103 | :path => path_param, | |
104 | :rev => @changeset.identifier) unless c.action == 'D' |
|
104 | :rev => @changeset.identifier) unless c.action == 'D' | |
105 | text << " - #{c.revision}" unless c.revision.blank? |
|
105 | text << " - #{c.revision}" unless c.revision.blank? | |
106 | text << ' (' + link_to('diff', :controller => 'repositories', |
|
106 | text << ' (' + link_to('diff', :controller => 'repositories', | |
107 | :action => 'diff', |
|
107 | :action => 'diff', | |
108 | :id => @project, |
|
108 | :id => @project, | |
109 | :path => path_param, |
|
109 | :path => path_param, | |
110 | :rev => @changeset.identifier) + ') ' if c.action == 'M' |
|
110 | :rev => @changeset.identifier) + ') ' if c.action == 'M' | |
111 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
|
111 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? | |
112 | output << "<li class='#{style}'>#{text}</li>" |
|
112 | output << "<li class='#{style}'>#{text}</li>" | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | output << '</ul>' |
|
115 | output << '</ul>' | |
116 | output |
|
116 | output | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def to_utf8(str) |
|
119 | def to_utf8(str) | |
120 | return str if str.blank? |
|
120 | return str if str.blank? | |
121 | if str.respond_to?(:force_encoding) |
|
121 | if str.respond_to?(:force_encoding) | |
122 | str.force_encoding('UTF-8') |
|
122 | str.force_encoding('UTF-8') | |
123 | else |
|
123 | else | |
124 | # TODO: |
|
124 | # TODO: | |
125 | # Japanese Shift_JIS(CP932) is not compatible with ASCII. |
|
125 | # Japanese Shift_JIS(CP932) is not compatible with ASCII. | |
126 | # UTF-7 and Japanese ISO-2022-JP are 7bits clean. |
|
126 | # UTF-7 and Japanese ISO-2022-JP are 7bits clean. | |
127 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
127 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
130 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) | |
131 | @encodings.each do |encoding| |
|
131 | @encodings.each do |encoding| | |
132 | begin |
|
132 | begin | |
133 | return Iconv.conv('UTF-8', encoding, str) |
|
133 | return Iconv.conv('UTF-8', encoding, str) | |
134 | rescue Iconv::Failure |
|
134 | rescue Iconv::Failure | |
135 | # do nothing here and try the next encoding |
|
135 | # do nothing here and try the next encoding | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 | str = replace_invalid_utf8(str) |
|
138 | str = replace_invalid_utf8(str) | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def replace_invalid_utf8(str) |
|
141 | def replace_invalid_utf8(str) | |
142 | if str.respond_to?(:force_encoding) |
|
142 | if str.respond_to?(:force_encoding) | |
143 | str.force_encoding('UTF-8') |
|
143 | str.force_encoding('UTF-8') | |
144 | if ! str.valid_encoding? |
|
144 | if ! str.valid_encoding? | |
145 | str = str.encode("US-ASCII", :invalid => :replace, |
|
145 | str = str.encode("US-ASCII", :invalid => :replace, | |
146 | :undef => :replace, :replace => '?').encode("UTF-8") |
|
146 | :undef => :replace, :replace => '?').encode("UTF-8") | |
147 | end |
|
147 | end | |
148 | end |
|
148 | end | |
149 | str |
|
149 | str | |
150 | end |
|
150 | end | |
151 |
|
151 | |||
152 | def repository_field_tags(form, repository) |
|
152 | def repository_field_tags(form, repository) | |
153 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
153 | method = repository.class.name.demodulize.underscore + "_field_tags" | |
154 | if repository.is_a?(Repository) && |
|
154 | if repository.is_a?(Repository) && | |
155 | respond_to?(method) && method != 'repository_field_tags' |
|
155 | respond_to?(method) && method != 'repository_field_tags' | |
156 | send(method, form, repository) |
|
156 | send(method, form, repository) | |
157 | end |
|
157 | end | |
158 | end |
|
158 | end | |
159 |
|
159 | |||
160 | def scm_select_tag(repository) |
|
160 | def scm_select_tag(repository) | |
161 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
|
161 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] | |
162 | Redmine::Scm::Base.all.each do |scm| |
|
162 | Redmine::Scm::Base.all.each do |scm| | |
163 | if Setting.enabled_scm.include?(scm) || |
|
163 | if Setting.enabled_scm.include?(scm) || | |
164 | (repository && repository.class.name.demodulize == scm) |
|
164 | (repository && repository.class.name.demodulize == scm) | |
165 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] |
|
165 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] | |
166 | end |
|
166 | end | |
167 | end |
|
167 | end | |
168 | select_tag('repository_scm', |
|
168 | select_tag('repository_scm', | |
169 | options_for_select(scm_options, repository.class.name.demodulize), |
|
169 | options_for_select(scm_options, repository.class.name.demodulize), | |
170 | :disabled => (repository && !repository.new_record?), |
|
170 | :disabled => (repository && !repository.new_record?), | |
171 | :onchange => remote_function( |
|
171 | :onchange => remote_function( | |
172 | :url => { |
|
172 | :url => { | |
173 | :controller => 'repositories', |
|
173 | :controller => 'repositories', | |
174 | :action => 'edit', |
|
174 | :action => 'edit', | |
175 | :id => @project |
|
175 | :id => @project | |
176 | }, |
|
176 | }, | |
177 | :method => :get, |
|
177 | :method => :get, | |
178 | :with => "Form.serialize(this.form)") |
|
178 | :with => "Form.serialize(this.form)") | |
179 | ) |
|
179 | ) | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | def with_leading_slash(path) |
|
182 | def with_leading_slash(path) | |
183 | path.to_s.starts_with?('/') ? path : "/#{path}" |
|
183 | path.to_s.starts_with?('/') ? path : "/#{path}" | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
186 | def without_leading_slash(path) |
|
186 | def without_leading_slash(path) | |
187 | path.gsub(%r{^/+}, '') |
|
187 | path.gsub(%r{^/+}, '') | |
188 | end |
|
188 | end | |
189 |
|
189 | |||
190 | def subversion_field_tags(form, repository) |
|
190 | def subversion_field_tags(form, repository) | |
191 | content_tag('p', form.text_field(:url, :size => 60, :required => true, |
|
191 | content_tag('p', form.text_field(:url, :size => 60, :required => true, | |
192 | :disabled => (repository && !repository.root_url.blank?)) + |
|
192 | :disabled => (repository && !repository.root_url.blank?)) + | |
193 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + |
|
193 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | |
194 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
194 | content_tag('p', form.text_field(:login, :size => 30)) + | |
195 | content_tag('p', form.password_field( |
|
195 | content_tag('p', form.password_field( | |
196 | :password, :size => 30, :name => 'ignore', |
|
196 | :password, :size => 30, :name => 'ignore', | |
197 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
197 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), | |
198 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
198 | :onfocus => "this.value=''; this.name='repository[password]';", | |
199 | :onchange => "this.name='repository[password]';")) |
|
199 | :onchange => "this.name='repository[password]';")) | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | def darcs_field_tags(form, repository) |
|
202 | def darcs_field_tags(form, repository) | |
203 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
203 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
204 | :size => 60, :required => true, |
|
204 | :size => 60, :required => true, | |
205 | :disabled => (repository && !repository.new_record?))) + |
|
205 | :disabled => (repository && !repository.new_record?))) + | |
206 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, |
|
206 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, | |
207 | :label => 'Commit messages encoding', :required => true)) |
|
207 | :label => 'Commit messages encoding', :required => true)) | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | def mercurial_field_tags(form, repository) |
|
210 | def mercurial_field_tags(form, repository) | |
211 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
211 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
212 | :size => 60, :required => true, |
|
212 | :size => 60, :required => true, | |
213 | :disabled => (repository && !repository.root_url.blank?)) + |
|
213 | :disabled => (repository && !repository.root_url.blank?)) + | |
214 | '<br />local repository (e.g. /hgrepo, c:\hgrepo)' ) + |
|
214 | '<br />local repository (e.g. /hgrepo, c:\hgrepo)' ) + | |
215 | content_tag('p', form.select( |
|
215 | content_tag('p', form.select( | |
216 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
216 | :path_encoding, [nil] + Setting::ENCODINGS, | |
217 | :label => 'Path encoding') + |
|
217 | :label => 'Path encoding') + | |
218 | '<br />Default: UTF-8') |
|
218 | '<br />Default: UTF-8') | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def git_field_tags(form, repository) |
|
221 | def git_field_tags(form, repository) | |
222 |
|
|
222 | content_tag('p', form.text_field(:url, :label => 'Path to repository', | |
223 | :size => 60, :required => true, |
|
223 | :size => 60, :required => true, | |
224 | :disabled => (repository && !repository.root_url.blank?)) + |
|
224 | :disabled => (repository && !repository.root_url.blank?)) + | |
225 | '<br />a bare and local repository (e.g. /gitrepo, c:\gitrepo)') |
|
225 | '<br />a bare and local repository (e.g. /gitrepo, c:\gitrepo)') + | |
|
226 | content_tag('p', form.select( | |||
|
227 | :path_encoding, [nil] + Setting::ENCODINGS, | |||
|
228 | :label => 'Path encoding') + | |||
|
229 | '<br />Default: UTF-8') | |||
226 | end |
|
230 | end | |
227 |
|
231 | |||
228 | def cvs_field_tags(form, repository) |
|
232 | def cvs_field_tags(form, repository) | |
229 | content_tag('p', form.text_field(:root_url, |
|
233 | content_tag('p', form.text_field(:root_url, | |
230 | :label => 'CVSROOT', :size => 60, :required => true, |
|
234 | :label => 'CVSROOT', :size => 60, :required => true, | |
231 | :disabled => !repository.new_record?)) + |
|
235 | :disabled => !repository.new_record?)) + | |
232 | content_tag('p', form.text_field(:url, :label => 'Module', |
|
236 | content_tag('p', form.text_field(:url, :label => 'Module', | |
233 | :size => 30, :required => true, |
|
237 | :size => 30, :required => true, | |
234 | :disabled => !repository.new_record?)) + |
|
238 | :disabled => !repository.new_record?)) + | |
235 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, |
|
239 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, | |
236 | :label => 'Commit messages encoding', :required => true)) |
|
240 | :label => 'Commit messages encoding', :required => true)) | |
237 | end |
|
241 | end | |
238 |
|
242 | |||
239 | def bazaar_field_tags(form, repository) |
|
243 | def bazaar_field_tags(form, repository) | |
240 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
244 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
241 | :size => 60, :required => true, |
|
245 | :size => 60, :required => true, | |
242 | :disabled => (repository && !repository.new_record?))) + |
|
246 | :disabled => (repository && !repository.new_record?))) + | |
243 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, |
|
247 | content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, | |
244 | :label => 'Commit messages encoding', :required => true)) |
|
248 | :label => 'Commit messages encoding', :required => true)) | |
245 | end |
|
249 | end | |
246 |
|
250 | |||
247 | def filesystem_field_tags(form, repository) |
|
251 | def filesystem_field_tags(form, repository) | |
248 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
252 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
249 | :size => 60, :required => true, |
|
253 | :size => 60, :required => true, | |
250 | :disabled => (repository && !repository.root_url.blank?))) + |
|
254 | :disabled => (repository && !repository.root_url.blank?))) + | |
251 | content_tag('p', form.select( |
|
255 | content_tag('p', form.select( | |
252 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
256 | :path_encoding, [nil] + Setting::ENCODINGS, | |
253 | :label => 'Path encoding') + |
|
257 | :label => 'Path encoding') + | |
254 | '<br />Default: UTF-8') |
|
258 | '<br />Default: UTF-8') | |
255 | end |
|
259 | end | |
256 | end |
|
260 | end |
General Comments 0
You need to be logged in to leave comments.
Login now