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