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