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