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