##// END OF EJS Templates
Fixed invalid html....
Jean-Philippe Lang -
r8386:87b51d847ccd
parent child
Show More
@@ -1,313 +1,314
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require 'iconv'
20 require 'iconv'
21 require 'redmine/codeset_util'
21 require 'redmine/codeset_util'
22
22
23 module RepositoriesHelper
23 module RepositoriesHelper
24 def format_revision(revision)
24 def format_revision(revision)
25 if revision.respond_to? :format_identifier
25 if revision.respond_to? :format_identifier
26 revision.format_identifier
26 revision.format_identifier
27 else
27 else
28 revision.to_s
28 revision.to_s
29 end
29 end
30 end
30 end
31
31
32 def truncate_at_line_break(text, length = 255)
32 def truncate_at_line_break(text, length = 255)
33 if text
33 if text
34 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
34 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
35 end
35 end
36 end
36 end
37
37
38 def render_properties(properties)
38 def render_properties(properties)
39 unless properties.nil? || properties.empty?
39 unless properties.nil? || properties.empty?
40 content = ''
40 content = ''
41 properties.keys.sort.each do |property|
41 properties.keys.sort.each do |property|
42 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
42 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
43 end
43 end
44 content_tag('ul', content.html_safe, :class => 'properties')
44 content_tag('ul', content.html_safe, :class => 'properties')
45 end
45 end
46 end
46 end
47
47
48 def render_changeset_changes
48 def render_changeset_changes
49 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
49 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
50 case change.action
50 case change.action
51 when 'A'
51 when 'A'
52 # Detects moved/copied files
52 # Detects moved/copied files
53 if !change.from_path.blank?
53 if !change.from_path.blank?
54 change.action =
54 change.action =
55 @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
55 @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
56 end
56 end
57 change
57 change
58 when 'D'
58 when 'D'
59 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
59 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
60 else
60 else
61 change
61 change
62 end
62 end
63 end.compact
63 end.compact
64
64
65 tree = { }
65 tree = { }
66 changes.each do |change|
66 changes.each do |change|
67 p = tree
67 p = tree
68 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
68 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
69 path = ''
69 path = ''
70 dirs.each do |dir|
70 dirs.each do |dir|
71 path += '/' + dir
71 path += '/' + dir
72 p[:s] ||= {}
72 p[:s] ||= {}
73 p = p[:s]
73 p = p[:s]
74 p[path] ||= {}
74 p[path] ||= {}
75 p = p[path]
75 p = p[path]
76 end
76 end
77 p[:c] = change
77 p[:c] = change
78 end
78 end
79 render_changes_tree(tree[:s])
79 render_changes_tree(tree[:s])
80 end
80 end
81
81
82 def render_changes_tree(tree)
82 def render_changes_tree(tree)
83 return '' if tree.nil?
83 return '' if tree.nil?
84 output = ''
84 output = ''
85 output << '<ul>'
85 output << '<ul>'
86 tree.keys.sort.each do |file|
86 tree.keys.sort.each do |file|
87 style = 'change'
87 style = 'change'
88 text = File.basename(h(file))
88 text = File.basename(h(file))
89 if s = tree[file][:s]
89 if s = tree[file][:s]
90 style << ' folder'
90 style << ' folder'
91 path_param = to_path_param(@repository.relative_path(file))
91 path_param = to_path_param(@repository.relative_path(file))
92 text = link_to(h(text), :controller => 'repositories',
92 text = link_to(h(text), :controller => 'repositories',
93 :action => 'show',
93 :action => 'show',
94 :id => @project,
94 :id => @project,
95 :path => path_param,
95 :path => path_param,
96 :rev => @changeset.identifier)
96 :rev => @changeset.identifier)
97 output << "<li class='#{style}'>#{text}</li>"
97 output << "<li class='#{style}'>#{text}"
98 output << render_changes_tree(s)
98 output << render_changes_tree(s)
99 output << "</li>"
99 elsif c = tree[file][:c]
100 elsif c = tree[file][:c]
100 style << " change-#{c.action}"
101 style << " change-#{c.action}"
101 path_param = to_path_param(@repository.relative_path(c.path))
102 path_param = to_path_param(@repository.relative_path(c.path))
102 text = link_to(h(text), :controller => 'repositories',
103 text = link_to(h(text), :controller => 'repositories',
103 :action => 'entry',
104 :action => 'entry',
104 :id => @project,
105 :id => @project,
105 :path => path_param,
106 :path => path_param,
106 :rev => @changeset.identifier) unless c.action == 'D'
107 :rev => @changeset.identifier) unless c.action == 'D'
107 text << " - #{h(c.revision)}" unless c.revision.blank?
108 text << " - #{h(c.revision)}" unless c.revision.blank?
108 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
109 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
109 :action => 'diff',
110 :action => 'diff',
110 :id => @project,
111 :id => @project,
111 :path => path_param,
112 :path => path_param,
112 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
113 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
113 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
114 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
114 output << "<li class='#{style}'>#{text}</li>"
115 output << "<li class='#{style}'>#{text}</li>"
115 end
116 end
116 end
117 end
117 output << '</ul>'
118 output << '</ul>'
118 output.html_safe
119 output.html_safe
119 end
120 end
120
121
121 def repository_field_tags(form, repository)
122 def repository_field_tags(form, repository)
122 method = repository.class.name.demodulize.underscore + "_field_tags"
123 method = repository.class.name.demodulize.underscore + "_field_tags"
123 if repository.is_a?(Repository) &&
124 if repository.is_a?(Repository) &&
124 respond_to?(method) && method != 'repository_field_tags'
125 respond_to?(method) && method != 'repository_field_tags'
125 send(method, form, repository)
126 send(method, form, repository)
126 end
127 end
127 end
128 end
128
129
129 def scm_select_tag(repository)
130 def scm_select_tag(repository)
130 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
131 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
131 Redmine::Scm::Base.all.each do |scm|
132 Redmine::Scm::Base.all.each do |scm|
132 if Setting.enabled_scm.include?(scm) ||
133 if Setting.enabled_scm.include?(scm) ||
133 (repository && repository.class.name.demodulize == scm)
134 (repository && repository.class.name.demodulize == scm)
134 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
135 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
135 end
136 end
136 end
137 end
137 select_tag('repository_scm',
138 select_tag('repository_scm',
138 options_for_select(scm_options, repository.class.name.demodulize),
139 options_for_select(scm_options, repository.class.name.demodulize),
139 :disabled => (repository && !repository.new_record?),
140 :disabled => (repository && !repository.new_record?),
140 :onchange => remote_function(
141 :onchange => remote_function(
141 :url => {
142 :url => {
142 :controller => 'repositories',
143 :controller => 'repositories',
143 :action => 'edit',
144 :action => 'edit',
144 :id => @project
145 :id => @project
145 },
146 },
146 :method => :get,
147 :method => :get,
147 :with => "Form.serialize(this.form)")
148 :with => "Form.serialize(this.form)")
148 )
149 )
149 end
150 end
150
151
151 def with_leading_slash(path)
152 def with_leading_slash(path)
152 path.to_s.starts_with?('/') ? path : "/#{path}"
153 path.to_s.starts_with?('/') ? path : "/#{path}"
153 end
154 end
154
155
155 def without_leading_slash(path)
156 def without_leading_slash(path)
156 path.gsub(%r{^/+}, '')
157 path.gsub(%r{^/+}, '')
157 end
158 end
158
159
159 def subversion_field_tags(form, repository)
160 def subversion_field_tags(form, repository)
160 content_tag('p', form.text_field(:url, :size => 60, :required => true,
161 content_tag('p', form.text_field(:url, :size => 60, :required => true,
161 :disabled => (repository && !repository.root_url.blank?)) +
162 :disabled => (repository && !repository.root_url.blank?)) +
162 '<br />'.html_safe +
163 '<br />'.html_safe +
163 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
164 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
164 content_tag('p', form.text_field(:login, :size => 30)) +
165 content_tag('p', form.text_field(:login, :size => 30)) +
165 content_tag('p', form.password_field(
166 content_tag('p', form.password_field(
166 :password, :size => 30, :name => 'ignore',
167 :password, :size => 30, :name => 'ignore',
167 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
168 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
168 :onfocus => "this.value=''; this.name='repository[password]';",
169 :onfocus => "this.value=''; this.name='repository[password]';",
169 :onchange => "this.name='repository[password]';"))
170 :onchange => "this.name='repository[password]';"))
170 end
171 end
171
172
172 def darcs_field_tags(form, repository)
173 def darcs_field_tags(form, repository)
173 content_tag('p', form.text_field(
174 content_tag('p', form.text_field(
174 :url, :label => l(:field_path_to_repository),
175 :url, :label => l(:field_path_to_repository),
175 :size => 60, :required => true,
176 :size => 60, :required => true,
176 :disabled => (repository && !repository.new_record?))) +
177 :disabled => (repository && !repository.new_record?))) +
177 content_tag('p', form.select(
178 content_tag('p', form.select(
178 :log_encoding, [nil] + Setting::ENCODINGS,
179 :log_encoding, [nil] + Setting::ENCODINGS,
179 :label => l(:field_commit_logs_encoding), :required => true))
180 :label => l(:field_commit_logs_encoding), :required => true))
180 end
181 end
181
182
182 def mercurial_field_tags(form, repository)
183 def mercurial_field_tags(form, repository)
183 content_tag('p', form.text_field(
184 content_tag('p', form.text_field(
184 :url, :label => l(:field_path_to_repository),
185 :url, :label => l(:field_path_to_repository),
185 :size => 60, :required => true,
186 :size => 60, :required => true,
186 :disabled => (repository && !repository.root_url.blank?)
187 :disabled => (repository && !repository.root_url.blank?)
187 ) +
188 ) +
188 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
189 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
189 content_tag('p', form.select(
190 content_tag('p', form.select(
190 :path_encoding, [nil] + Setting::ENCODINGS,
191 :path_encoding, [nil] + Setting::ENCODINGS,
191 :label => l(:field_scm_path_encoding)
192 :label => l(:field_scm_path_encoding)
192 ) +
193 ) +
193 '<br />'.html_safe + l(:text_scm_path_encoding_note))
194 '<br />'.html_safe + l(:text_scm_path_encoding_note))
194 end
195 end
195
196
196 def git_field_tags(form, repository)
197 def git_field_tags(form, repository)
197 content_tag('p', form.text_field(
198 content_tag('p', form.text_field(
198 :url, :label => l(:field_path_to_repository),
199 :url, :label => l(:field_path_to_repository),
199 :size => 60, :required => true,
200 :size => 60, :required => true,
200 :disabled => (repository && !repository.root_url.blank?)
201 :disabled => (repository && !repository.root_url.blank?)
201 ) +
202 ) +
202 '<br />'.html_safe +
203 '<br />'.html_safe +
203 l(:text_git_repository_note)) +
204 l(:text_git_repository_note)) +
204 content_tag('p', form.select(
205 content_tag('p', form.select(
205 :path_encoding, [nil] + Setting::ENCODINGS,
206 :path_encoding, [nil] + Setting::ENCODINGS,
206 :label => l(:field_scm_path_encoding)
207 :label => l(:field_scm_path_encoding)
207 ) +
208 ) +
208 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
209 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
209 content_tag('p', form.check_box(
210 content_tag('p', form.check_box(
210 :extra_report_last_commit,
211 :extra_report_last_commit,
211 :label => l(:label_git_report_last_commit)
212 :label => l(:label_git_report_last_commit)
212 ))
213 ))
213 end
214 end
214
215
215 def cvs_field_tags(form, repository)
216 def cvs_field_tags(form, repository)
216 content_tag('p', form.text_field(
217 content_tag('p', form.text_field(
217 :root_url,
218 :root_url,
218 :label => l(:field_cvsroot),
219 :label => l(:field_cvsroot),
219 :size => 60, :required => true,
220 :size => 60, :required => true,
220 :disabled => !repository.new_record?)) +
221 :disabled => !repository.new_record?)) +
221 content_tag('p', form.text_field(
222 content_tag('p', form.text_field(
222 :url,
223 :url,
223 :label => l(:field_cvs_module),
224 :label => l(:field_cvs_module),
224 :size => 30, :required => true,
225 :size => 30, :required => true,
225 :disabled => !repository.new_record?)) +
226 :disabled => !repository.new_record?)) +
226 content_tag('p', form.select(
227 content_tag('p', form.select(
227 :log_encoding, [nil] + Setting::ENCODINGS,
228 :log_encoding, [nil] + Setting::ENCODINGS,
228 :label => l(:field_commit_logs_encoding), :required => true)) +
229 :label => l(:field_commit_logs_encoding), :required => true)) +
229 content_tag('p', form.select(
230 content_tag('p', form.select(
230 :path_encoding, [nil] + Setting::ENCODINGS,
231 :path_encoding, [nil] + Setting::ENCODINGS,
231 :label => l(:field_scm_path_encoding)
232 :label => l(:field_scm_path_encoding)
232 ) +
233 ) +
233 '<br />'.html_safe + l(:text_scm_path_encoding_note))
234 '<br />'.html_safe + l(:text_scm_path_encoding_note))
234 end
235 end
235
236
236 def bazaar_field_tags(form, repository)
237 def bazaar_field_tags(form, repository)
237 content_tag('p', form.text_field(
238 content_tag('p', form.text_field(
238 :url, :label => l(:field_path_to_repository),
239 :url, :label => l(:field_path_to_repository),
239 :size => 60, :required => true,
240 :size => 60, :required => true,
240 :disabled => (repository && !repository.new_record?))) +
241 :disabled => (repository && !repository.new_record?))) +
241 content_tag('p', form.select(
242 content_tag('p', form.select(
242 :log_encoding, [nil] + Setting::ENCODINGS,
243 :log_encoding, [nil] + Setting::ENCODINGS,
243 :label => l(:field_commit_logs_encoding), :required => true))
244 :label => l(:field_commit_logs_encoding), :required => true))
244 end
245 end
245
246
246 def filesystem_field_tags(form, repository)
247 def filesystem_field_tags(form, repository)
247 content_tag('p', form.text_field(
248 content_tag('p', form.text_field(
248 :url, :label => l(:field_root_directory),
249 :url, :label => l(:field_root_directory),
249 :size => 60, :required => true,
250 :size => 60, :required => true,
250 :disabled => (repository && !repository.root_url.blank?))) +
251 :disabled => (repository && !repository.root_url.blank?))) +
251 content_tag('p', form.select(
252 content_tag('p', form.select(
252 :path_encoding, [nil] + Setting::ENCODINGS,
253 :path_encoding, [nil] + Setting::ENCODINGS,
253 :label => l(:field_scm_path_encoding)
254 :label => l(:field_scm_path_encoding)
254 ) +
255 ) +
255 '<br />'.html_safe + l(:text_scm_path_encoding_note))
256 '<br />'.html_safe + l(:text_scm_path_encoding_note))
256 end
257 end
257
258
258 def index_commits(commits, heads, href_proc = nil)
259 def index_commits(commits, heads, href_proc = nil)
259 return nil if commits.nil? or commits.first.parents.nil?
260 return nil if commits.nil? or commits.first.parents.nil?
260 map = {}
261 map = {}
261 commit_hashes = []
262 commit_hashes = []
262 refs_map = {}
263 refs_map = {}
263 href_proc ||= Proc.new {|x|x}
264 href_proc ||= Proc.new {|x|x}
264 heads.each{|r| refs_map[r.scmid] ||= []; refs_map[r.scmid] << r}
265 heads.each{|r| refs_map[r.scmid] ||= []; refs_map[r.scmid] << r}
265 commits.reverse.each_with_index do |c, i|
266 commits.reverse.each_with_index do |c, i|
266 h = {}
267 h = {}
267 h[:parents] = c.parents.collect do |p|
268 h[:parents] = c.parents.collect do |p|
268 [p.scmid, 0, 0]
269 [p.scmid, 0, 0]
269 end
270 end
270 h[:rdmid] = i
271 h[:rdmid] = i
271 h[:space] = 0
272 h[:space] = 0
272 h[:refs] = refs_map[c.scmid].join(" ") if refs_map.include? c.scmid
273 h[:refs] = refs_map[c.scmid].join(" ") if refs_map.include? c.scmid
273 h[:scmid] = c.scmid
274 h[:scmid] = c.scmid
274 h[:href] = href_proc.call(c.scmid)
275 h[:href] = href_proc.call(c.scmid)
275 commit_hashes << h
276 commit_hashes << h
276 map[c.scmid] = h
277 map[c.scmid] = h
277 end
278 end
278 heads.sort! do |a,b|
279 heads.sort! do |a,b|
279 a.to_s <=> b.to_s
280 a.to_s <=> b.to_s
280 end
281 end
281 j = 0
282 j = 0
282 heads.each do |h|
283 heads.each do |h|
283 if map.include? h.scmid then
284 if map.include? h.scmid then
284 j = mark_chain(j += 1, map[h.scmid], map)
285 j = mark_chain(j += 1, map[h.scmid], map)
285 end
286 end
286 end
287 end
287 # when no head matched anything use first commit
288 # when no head matched anything use first commit
288 if j == 0 then
289 if j == 0 then
289 mark_chain(j += 1, map.values.first, map)
290 mark_chain(j += 1, map.values.first, map)
290 end
291 end
291 map
292 map
292 end
293 end
293
294
294 def mark_chain(mark, commit, map)
295 def mark_chain(mark, commit, map)
295 stack = [[mark, commit]]
296 stack = [[mark, commit]]
296 markmax = mark
297 markmax = mark
297 until stack.empty?
298 until stack.empty?
298 current = stack.pop
299 current = stack.pop
299 m, commit = current
300 m, commit = current
300 commit[:space] = m if commit[:space] == 0
301 commit[:space] = m if commit[:space] == 0
301 m1 = m - 1
302 m1 = m - 1
302 commit[:parents].each_with_index do |p, i|
303 commit[:parents].each_with_index do |p, i|
303 psha = p[0]
304 psha = p[0]
304 if map.include? psha and map[psha][:space] == 0 then
305 if map.include? psha and map[psha][:space] == 0 then
305 stack << [m1 += 1, map[psha]] if i == 0
306 stack << [m1 += 1, map[psha]] if i == 0
306 stack = [[m1 += 1, map[psha]]] + stack if i > 0
307 stack = [[m1 += 1, map[psha]]] + stack if i > 0
307 end
308 end
308 end
309 end
309 markmax = m1 if markmax < m1
310 markmax = m1 if markmax < m1
310 end
311 end
311 markmax
312 markmax
312 end
313 end
313 end
314 end
General Comments 0
You need to be logged in to leave comments. Login now