##// END OF EJS Templates
remove redundant empty lines from RepositoriesHelper...
Toshi MARUYAMA -
r10199:5441f8de4df5
parent child
Show More
@@ -1,312 +1,299
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 # Copyright (C) 2006-2012 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 'redmine/codeset_util'
20 require 'redmine/codeset_util'
21
21
22 module RepositoriesHelper
22 module RepositoriesHelper
23 def format_revision(revision)
23 def format_revision(revision)
24 if revision.respond_to? :format_identifier
24 if revision.respond_to? :format_identifier
25 revision.format_identifier
25 revision.format_identifier
26 else
26 else
27 revision.to_s
27 revision.to_s
28 end
28 end
29 end
29 end
30
30
31 def truncate_at_line_break(text, length = 255)
31 def truncate_at_line_break(text, length = 255)
32 if text
32 if text
33 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
33 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
34 end
34 end
35 end
35 end
36
36
37 def render_properties(properties)
37 def render_properties(properties)
38 unless properties.nil? || properties.empty?
38 unless properties.nil? || properties.empty?
39 content = ''
39 content = ''
40 properties.keys.sort.each do |property|
40 properties.keys.sort.each do |property|
41 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
41 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
42 end
42 end
43 content_tag('ul', content.html_safe, :class => 'properties')
43 content_tag('ul', content.html_safe, :class => 'properties')
44 end
44 end
45 end
45 end
46
46
47 def render_changeset_changes
47 def render_changeset_changes
48 changes = @changeset.filechanges.find(:all, :limit => 1000, :order => 'path').collect do |change|
48 changes = @changeset.filechanges.find(:all, :limit => 1000, :order => 'path').collect do |change|
49 case change.action
49 case change.action
50 when 'A'
50 when 'A'
51 # Detects moved/copied files
51 # Detects moved/copied files
52 if !change.from_path.blank?
52 if !change.from_path.blank?
53 change.action =
53 change.action =
54 @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
54 @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
55 end
55 end
56 change
56 change
57 when 'D'
57 when 'D'
58 @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
58 @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
59 else
59 else
60 change
60 change
61 end
61 end
62 end.compact
62 end.compact
63
63
64 tree = { }
64 tree = { }
65 changes.each do |change|
65 changes.each do |change|
66 p = tree
66 p = tree
67 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
67 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
68 path = ''
68 path = ''
69 dirs.each do |dir|
69 dirs.each do |dir|
70 path += '/' + dir
70 path += '/' + dir
71 p[:s] ||= {}
71 p[:s] ||= {}
72 p = p[:s]
72 p = p[:s]
73 p[path] ||= {}
73 p[path] ||= {}
74 p = p[path]
74 p = p[path]
75 end
75 end
76 p[:c] = change
76 p[:c] = change
77 end
77 end
78 render_changes_tree(tree[:s])
78 render_changes_tree(tree[:s])
79 end
79 end
80
80
81 def render_changes_tree(tree)
81 def render_changes_tree(tree)
82 return '' if tree.nil?
82 return '' if tree.nil?
83 output = ''
83 output = ''
84 output << '<ul>'
84 output << '<ul>'
85 tree.keys.sort.each do |file|
85 tree.keys.sort.each do |file|
86 style = 'change'
86 style = 'change'
87 text = File.basename(h(file))
87 text = File.basename(h(file))
88 if s = tree[file][:s]
88 if s = tree[file][:s]
89 style << ' folder'
89 style << ' folder'
90 path_param = to_path_param(@repository.relative_path(file))
90 path_param = to_path_param(@repository.relative_path(file))
91 text = link_to(h(text), :controller => 'repositories',
91 text = link_to(h(text), :controller => 'repositories',
92 :action => 'show',
92 :action => 'show',
93 :id => @project,
93 :id => @project,
94 :repository_id => @repository.identifier_param,
94 :repository_id => @repository.identifier_param,
95 :path => path_param,
95 :path => path_param,
96 :rev => @changeset.identifier)
96 :rev => @changeset.identifier)
97 output << "<li class='#{style}'>#{text}"
97 output << "<li class='#{style}'>#{text}"
98 output << render_changes_tree(s)
98 output << render_changes_tree(s)
99 output << "</li>"
99 output << "</li>"
100 elsif c = tree[file][:c]
100 elsif c = tree[file][:c]
101 style << " change-#{c.action}"
101 style << " change-#{c.action}"
102 path_param = to_path_param(@repository.relative_path(c.path))
102 path_param = to_path_param(@repository.relative_path(c.path))
103 text = link_to(h(text), :controller => 'repositories',
103 text = link_to(h(text), :controller => 'repositories',
104 :action => 'entry',
104 :action => 'entry',
105 :id => @project,
105 :id => @project,
106 :repository_id => @repository.identifier_param,
106 :repository_id => @repository.identifier_param,
107 :path => path_param,
107 :path => path_param,
108 :rev => @changeset.identifier) unless c.action == 'D'
108 :rev => @changeset.identifier) unless c.action == 'D'
109 text << " - #{h(c.revision)}" unless c.revision.blank?
109 text << " - #{h(c.revision)}" unless c.revision.blank?
110 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
110 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
111 :action => 'diff',
111 :action => 'diff',
112 :id => @project,
112 :id => @project,
113 :repository_id => @repository.identifier_param,
113 :repository_id => @repository.identifier_param,
114 :path => path_param,
114 :path => path_param,
115 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
115 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
116 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
116 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
117 output << "<li class='#{style}'>#{text}</li>"
117 output << "<li class='#{style}'>#{text}</li>"
118 end
118 end
119 end
119 end
120 output << '</ul>'
120 output << '</ul>'
121 output.html_safe
121 output.html_safe
122 end
122 end
123
123
124 def repository_field_tags(form, repository)
124 def repository_field_tags(form, repository)
125 method = repository.class.name.demodulize.underscore + "_field_tags"
125 method = repository.class.name.demodulize.underscore + "_field_tags"
126 if repository.is_a?(Repository) &&
126 if repository.is_a?(Repository) &&
127 respond_to?(method) && method != 'repository_field_tags'
127 respond_to?(method) && method != 'repository_field_tags'
128 send(method, form, repository)
128 send(method, form, repository)
129 end
129 end
130 end
130 end
131
131
132 def scm_select_tag(repository)
132 def scm_select_tag(repository)
133 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
133 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
134 Redmine::Scm::Base.all.each do |scm|
134 Redmine::Scm::Base.all.each do |scm|
135 if Setting.enabled_scm.include?(scm) ||
135 if Setting.enabled_scm.include?(scm) ||
136 (repository && repository.class.name.demodulize == scm)
136 (repository && repository.class.name.demodulize == scm)
137 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
137 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
138 end
138 end
139 end
139 end
140 select_tag('repository_scm',
140 select_tag('repository_scm',
141 options_for_select(scm_options, repository.class.name.demodulize),
141 options_for_select(scm_options, repository.class.name.demodulize),
142 :disabled => (repository && !repository.new_record?),
142 :disabled => (repository && !repository.new_record?),
143 :data => {:remote => true, :method => 'get'})
143 :data => {:remote => true, :method => 'get'})
144 end
144 end
145
145
146 def with_leading_slash(path)
146 def with_leading_slash(path)
147 path.to_s.starts_with?('/') ? path : "/#{path}"
147 path.to_s.starts_with?('/') ? path : "/#{path}"
148 end
148 end
149
149
150 def without_leading_slash(path)
150 def without_leading_slash(path)
151 path.gsub(%r{^/+}, '')
151 path.gsub(%r{^/+}, '')
152 end
152 end
153
153
154 def subversion_field_tags(form, repository)
154 def subversion_field_tags(form, repository)
155 content_tag('p', form.text_field(:url, :size => 60, :required => true,
155 content_tag('p', form.text_field(:url, :size => 60, :required => true,
156 :disabled => !repository.safe_attribute?('url')) +
156 :disabled => !repository.safe_attribute?('url')) +
157 '<br />'.html_safe +
157 '<br />'.html_safe +
158 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
158 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
159 content_tag('p', form.text_field(:login, :size => 30)) +
159 content_tag('p', form.text_field(:login, :size => 30)) +
160 content_tag('p', form.password_field(
160 content_tag('p', form.password_field(
161 :password, :size => 30, :name => 'ignore',
161 :password, :size => 30, :name => 'ignore',
162 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
162 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
163 :onfocus => "this.value=''; this.name='repository[password]';",
163 :onfocus => "this.value=''; this.name='repository[password]';",
164 :onchange => "this.name='repository[password]';"))
164 :onchange => "this.name='repository[password]';"))
165 end
165 end
166
166
167 def darcs_field_tags(form, repository)
167 def darcs_field_tags(form, repository)
168 content_tag('p', form.text_field(
168 content_tag('p', form.text_field(
169 :url, :label => l(:field_path_to_repository),
169 :url, :label => l(:field_path_to_repository),
170 :size => 60, :required => true,
170 :size => 60, :required => true,
171 :disabled => !repository.safe_attribute?('url'))) +
171 :disabled => !repository.safe_attribute?('url'))) +
172 content_tag('p', form.select(
172 content_tag('p', form.select(
173 :log_encoding, [nil] + Setting::ENCODINGS,
173 :log_encoding, [nil] + Setting::ENCODINGS,
174 :label => l(:field_commit_logs_encoding), :required => true))
174 :label => l(:field_commit_logs_encoding), :required => true))
175 end
175 end
176
176
177 def mercurial_field_tags(form, repository)
177 def mercurial_field_tags(form, repository)
178 content_tag('p', form.text_field(
178 content_tag('p', form.text_field(
179 :url, :label => l(:field_path_to_repository),
179 :url, :label => l(:field_path_to_repository),
180 :size => 60, :required => true,
180 :size => 60, :required => true,
181 :disabled => !repository.safe_attribute?('url')
181 :disabled => !repository.safe_attribute?('url')
182 ) +
182 ) +
183 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
183 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
184 content_tag('p', form.select(
184 content_tag('p', form.select(
185 :path_encoding, [nil] + Setting::ENCODINGS,
185 :path_encoding, [nil] + Setting::ENCODINGS,
186 :label => l(:field_scm_path_encoding)
186 :label => l(:field_scm_path_encoding)
187 ) +
187 ) +
188 '<br />'.html_safe + l(:text_scm_path_encoding_note))
188 '<br />'.html_safe + l(:text_scm_path_encoding_note))
189 end
189 end
190
190
191 def git_field_tags(form, repository)
191 def git_field_tags(form, repository)
192 content_tag('p', form.text_field(
192 content_tag('p', form.text_field(
193 :url, :label => l(:field_path_to_repository),
193 :url, :label => l(:field_path_to_repository),
194 :size => 60, :required => true,
194 :size => 60, :required => true,
195 :disabled => !repository.safe_attribute?('url')
195 :disabled => !repository.safe_attribute?('url')
196 ) +
196 ) +
197 '<br />'.html_safe +
197 '<br />'.html_safe +
198 l(:text_git_repository_note)) +
198 l(:text_git_repository_note)) +
199 content_tag('p', form.select(
199 content_tag('p', form.select(
200 :path_encoding, [nil] + Setting::ENCODINGS,
200 :path_encoding, [nil] + Setting::ENCODINGS,
201 :label => l(:field_scm_path_encoding)
201 :label => l(:field_scm_path_encoding)
202 ) +
202 ) +
203 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
203 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
204 content_tag('p', form.check_box(
204 content_tag('p', form.check_box(
205 :extra_report_last_commit,
205 :extra_report_last_commit,
206 :label => l(:label_git_report_last_commit)
206 :label => l(:label_git_report_last_commit)
207 ))
207 ))
208 end
208 end
209
209
210 def cvs_field_tags(form, repository)
210 def cvs_field_tags(form, repository)
211 content_tag('p', form.text_field(
211 content_tag('p', form.text_field(
212 :root_url,
212 :root_url,
213 :label => l(:field_cvsroot),
213 :label => l(:field_cvsroot),
214 :size => 60, :required => true,
214 :size => 60, :required => true,
215 :disabled => !repository.safe_attribute?('root_url'))) +
215 :disabled => !repository.safe_attribute?('root_url'))) +
216 content_tag('p', form.text_field(
216 content_tag('p', form.text_field(
217 :url,
217 :url,
218 :label => l(:field_cvs_module),
218 :label => l(:field_cvs_module),
219 :size => 30, :required => true,
219 :size => 30, :required => true,
220 :disabled => !repository.safe_attribute?('url'))) +
220 :disabled => !repository.safe_attribute?('url'))) +
221 content_tag('p', form.select(
221 content_tag('p', form.select(
222 :log_encoding, [nil] + Setting::ENCODINGS,
222 :log_encoding, [nil] + Setting::ENCODINGS,
223 :label => l(:field_commit_logs_encoding), :required => true)) +
223 :label => l(:field_commit_logs_encoding), :required => true)) +
224 content_tag('p', form.select(
224 content_tag('p', form.select(
225 :path_encoding, [nil] + Setting::ENCODINGS,
225 :path_encoding, [nil] + Setting::ENCODINGS,
226 :label => l(:field_scm_path_encoding)
226 :label => l(:field_scm_path_encoding)
227 ) +
227 ) +
228 '<br />'.html_safe + l(:text_scm_path_encoding_note))
228 '<br />'.html_safe + l(:text_scm_path_encoding_note))
229 end
229 end
230
230
231 def bazaar_field_tags(form, repository)
231 def bazaar_field_tags(form, repository)
232 content_tag('p', form.text_field(
232 content_tag('p', form.text_field(
233 :url, :label => l(:field_path_to_repository),
233 :url, :label => l(:field_path_to_repository),
234 :size => 60, :required => true,
234 :size => 60, :required => true,
235 :disabled => !repository.safe_attribute?('url'))) +
235 :disabled => !repository.safe_attribute?('url'))) +
236 content_tag('p', form.select(
236 content_tag('p', form.select(
237 :log_encoding, [nil] + Setting::ENCODINGS,
237 :log_encoding, [nil] + Setting::ENCODINGS,
238 :label => l(:field_commit_logs_encoding), :required => true))
238 :label => l(:field_commit_logs_encoding), :required => true))
239 end
239 end
240
240
241 def filesystem_field_tags(form, repository)
241 def filesystem_field_tags(form, repository)
242 content_tag('p', form.text_field(
242 content_tag('p', form.text_field(
243 :url, :label => l(:field_root_directory),
243 :url, :label => l(:field_root_directory),
244 :size => 60, :required => true,
244 :size => 60, :required => true,
245 :disabled => !repository.safe_attribute?('url'))) +
245 :disabled => !repository.safe_attribute?('url'))) +
246 content_tag('p', form.select(
246 content_tag('p', form.select(
247 :path_encoding, [nil] + Setting::ENCODINGS,
247 :path_encoding, [nil] + Setting::ENCODINGS,
248 :label => l(:field_scm_path_encoding)
248 :label => l(:field_scm_path_encoding)
249 ) +
249 ) +
250 '<br />'.html_safe + l(:text_scm_path_encoding_note))
250 '<br />'.html_safe + l(:text_scm_path_encoding_note))
251 end
251 end
252
252
253 def index_commits(commits, heads)
253 def index_commits(commits, heads)
254 return nil if commits.nil? or commits.first.parents.nil?
254 return nil if commits.nil? or commits.first.parents.nil?
255
256 refs_map = {}
255 refs_map = {}
257 heads.each do |head|
256 heads.each do |head|
258 refs_map[head.scmid] ||= []
257 refs_map[head.scmid] ||= []
259 refs_map[head.scmid] << head
258 refs_map[head.scmid] << head
260 end
259 end
261
262 commits_by_scmid = {}
260 commits_by_scmid = {}
263 commits.reverse.each_with_index do |commit, commit_index|
261 commits.reverse.each_with_index do |commit, commit_index|
264
265 commits_by_scmid[commit.scmid] = {
262 commits_by_scmid[commit.scmid] = {
266 :parent_scmids => commit.parents.collect { |parent| parent.scmid },
263 :parent_scmids => commit.parents.collect { |parent| parent.scmid },
267 :rdmid => commit_index,
264 :rdmid => commit_index,
268 :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
265 :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
269 :scmid => commit.scmid,
266 :scmid => commit.scmid,
270 :href => block_given? ? yield(commit.scmid) : commit.scmid
267 :href => block_given? ? yield(commit.scmid) : commit.scmid
271 }
268 }
272 end
269 end
273
274 heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
270 heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
275
276 space = nil
271 space = nil
277 heads.each do |head|
272 heads.each do |head|
278 if commits_by_scmid.include? head.scmid
273 if commits_by_scmid.include? head.scmid
279 space = index_head((space || -1) + 1, head, commits_by_scmid)
274 space = index_head((space || -1) + 1, head, commits_by_scmid)
280 end
275 end
281 end
276 end
282
283 # when no head matched anything use first commit
277 # when no head matched anything use first commit
284 space ||= index_head(0, commits.first, commits_by_scmid)
278 space ||= index_head(0, commits.first, commits_by_scmid)
285
286 return commits_by_scmid, space
279 return commits_by_scmid, space
287 end
280 end
288
281
289 def index_head(space, commit, commits_by_scmid)
282 def index_head(space, commit, commits_by_scmid)
290
291 stack = [[space, commits_by_scmid[commit.scmid]]]
283 stack = [[space, commits_by_scmid[commit.scmid]]]
292 max_space = space
284 max_space = space
293
294 until stack.empty?
285 until stack.empty?
295 space, commit = stack.pop
286 space, commit = stack.pop
296 commit[:space] = space if commit[:space].nil?
287 commit[:space] = space if commit[:space].nil?
297
298 space -= 1
288 space -= 1
299 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
289 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
300
301 parent_commit = commits_by_scmid[parent_scmid]
290 parent_commit = commits_by_scmid[parent_scmid]
302
303 if parent_commit and parent_commit[:space].nil?
291 if parent_commit and parent_commit[:space].nil?
304
305 stack.unshift [space += 1, parent_commit]
292 stack.unshift [space += 1, parent_commit]
306 end
293 end
307 end
294 end
308 max_space = space if max_space < space
295 max_space = space if max_space < space
309 end
296 end
310 max_space
297 max_space
311 end
298 end
312 end
299 end
General Comments 0
You need to be logged in to leave comments. Login now