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