@@ -1,297 +1,295 | |||
|
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 | 148 | def without_leading_slash(path) |
|
149 | 149 | path.gsub(%r{^/+}, '') |
|
150 | 150 | end |
|
151 | 151 | |
|
152 | 152 | def subversion_field_tags(form, repository) |
|
153 | 153 | content_tag('p', form.text_field(:url, :size => 60, :required => true, |
|
154 | 154 | :disabled => !repository.safe_attribute?('url')) + |
|
155 | '<br />'.html_safe + | |
|
156 | '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | |
|
155 | content_tag('em', '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)', :class => 'info')) + | |
|
157 | 156 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
158 | 157 | content_tag('p', form.password_field( |
|
159 | 158 | :password, :size => 30, :name => 'ignore', |
|
160 | 159 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
161 | 160 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
162 | 161 | :onchange => "this.name='repository[password]';")) |
|
163 | 162 | end |
|
164 | 163 | |
|
165 | 164 | def darcs_field_tags(form, repository) |
|
166 | 165 | content_tag('p', form.text_field( |
|
167 | 166 | :url, :label => l(:field_path_to_repository), |
|
168 | 167 | :size => 60, :required => true, |
|
169 | 168 | :disabled => !repository.safe_attribute?('url'))) + |
|
170 | 169 | content_tag('p', form.select( |
|
171 | 170 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
172 | 171 | :label => l(:field_commit_logs_encoding), :required => true)) |
|
173 | 172 | end |
|
174 | 173 | |
|
175 | 174 | def mercurial_field_tags(form, repository) |
|
176 | 175 | content_tag('p', form.text_field( |
|
177 | 176 | :url, :label => l(:field_path_to_repository), |
|
178 | 177 | :size => 60, :required => true, |
|
179 | 178 | :disabled => !repository.safe_attribute?('url') |
|
180 | 179 | ) + |
|
181 |
|
|
|
180 | content_tag('em', l(:text_mercurial_repository_note), :class => 'info')) + | |
|
182 | 181 | content_tag('p', form.select( |
|
183 | 182 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
184 | 183 | :label => l(:field_scm_path_encoding) |
|
185 | 184 | ) + |
|
186 |
|
|
|
185 | content_tag('em', l(:text_scm_path_encoding_note), :class => 'info')) | |
|
187 | 186 | end |
|
188 | 187 | |
|
189 | 188 | def git_field_tags(form, repository) |
|
190 | 189 | content_tag('p', form.text_field( |
|
191 | 190 | :url, :label => l(:field_path_to_repository), |
|
192 | 191 | :size => 60, :required => true, |
|
193 | 192 | :disabled => !repository.safe_attribute?('url') |
|
194 | 193 | ) + |
|
195 | '<br />'.html_safe + | |
|
196 | l(:text_git_repository_note)) + | |
|
194 | content_tag('em', l(:text_git_repository_note), :class => 'info')) + | |
|
197 | 195 | content_tag('p', form.select( |
|
198 | 196 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
199 | 197 | :label => l(:field_scm_path_encoding) |
|
200 | 198 | ) + |
|
201 |
|
|
|
199 | content_tag('em', l(:text_scm_path_encoding_note), :class => 'info')) + | |
|
202 | 200 | content_tag('p', form.check_box( |
|
203 | 201 | :extra_report_last_commit, |
|
204 | 202 | :label => l(:label_git_report_last_commit) |
|
205 | 203 | )) |
|
206 | 204 | end |
|
207 | 205 | |
|
208 | 206 | def cvs_field_tags(form, repository) |
|
209 | 207 | content_tag('p', form.text_field( |
|
210 | 208 | :root_url, |
|
211 | 209 | :label => l(:field_cvsroot), |
|
212 | 210 | :size => 60, :required => true, |
|
213 | 211 | :disabled => !repository.safe_attribute?('root_url'))) + |
|
214 | 212 | content_tag('p', form.text_field( |
|
215 | 213 | :url, |
|
216 | 214 | :label => l(:field_cvs_module), |
|
217 | 215 | :size => 30, :required => true, |
|
218 | 216 | :disabled => !repository.safe_attribute?('url'))) + |
|
219 | 217 | content_tag('p', form.select( |
|
220 | 218 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
221 | 219 | :label => l(:field_commit_logs_encoding), :required => true)) + |
|
222 | 220 | content_tag('p', form.select( |
|
223 | 221 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
224 | 222 | :label => l(:field_scm_path_encoding) |
|
225 | 223 | ) + |
|
226 |
|
|
|
224 | content_tag('em', l(:text_scm_path_encoding_note), :class => 'info')) | |
|
227 | 225 | end |
|
228 | 226 | |
|
229 | 227 | def bazaar_field_tags(form, repository) |
|
230 | 228 | content_tag('p', form.text_field( |
|
231 | 229 | :url, :label => l(:field_path_to_repository), |
|
232 | 230 | :size => 60, :required => true, |
|
233 | 231 | :disabled => !repository.safe_attribute?('url'))) + |
|
234 | 232 | content_tag('p', form.select( |
|
235 | 233 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
236 | 234 | :label => l(:field_commit_logs_encoding), :required => true)) |
|
237 | 235 | end |
|
238 | 236 | |
|
239 | 237 | def filesystem_field_tags(form, repository) |
|
240 | 238 | content_tag('p', form.text_field( |
|
241 | 239 | :url, :label => l(:field_root_directory), |
|
242 | 240 | :size => 60, :required => true, |
|
243 | 241 | :disabled => !repository.safe_attribute?('url'))) + |
|
244 | 242 | content_tag('p', form.select( |
|
245 | 243 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
246 | 244 | :label => l(:field_scm_path_encoding) |
|
247 | 245 | ) + |
|
248 |
|
|
|
246 | content_tag('em', l(:text_scm_path_encoding_note), :class => 'info')) | |
|
249 | 247 | end |
|
250 | 248 | |
|
251 | 249 | def index_commits(commits, heads) |
|
252 | 250 | return nil if commits.nil? or commits.first.parents.nil? |
|
253 | 251 | refs_map = {} |
|
254 | 252 | heads.each do |head| |
|
255 | 253 | refs_map[head.scmid] ||= [] |
|
256 | 254 | refs_map[head.scmid] << head |
|
257 | 255 | end |
|
258 | 256 | commits_by_scmid = {} |
|
259 | 257 | commits.reverse.each_with_index do |commit, commit_index| |
|
260 | 258 | commits_by_scmid[commit.scmid] = { |
|
261 | 259 | :parent_scmids => commit.parents.collect { |parent| parent.scmid }, |
|
262 | 260 | :rdmid => commit_index, |
|
263 | 261 | :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil, |
|
264 | 262 | :scmid => commit.scmid, |
|
265 | 263 | :href => block_given? ? yield(commit.scmid) : commit.scmid |
|
266 | 264 | } |
|
267 | 265 | end |
|
268 | 266 | heads.sort! { |head1, head2| head1.to_s <=> head2.to_s } |
|
269 | 267 | space = nil |
|
270 | 268 | heads.each do |head| |
|
271 | 269 | if commits_by_scmid.include? head.scmid |
|
272 | 270 | space = index_head((space || -1) + 1, head, commits_by_scmid) |
|
273 | 271 | end |
|
274 | 272 | end |
|
275 | 273 | # when no head matched anything use first commit |
|
276 | 274 | space ||= index_head(0, commits.first, commits_by_scmid) |
|
277 | 275 | return commits_by_scmid, space |
|
278 | 276 | end |
|
279 | 277 | |
|
280 | 278 | def index_head(space, commit, commits_by_scmid) |
|
281 | 279 | stack = [[space, commits_by_scmid[commit.scmid]]] |
|
282 | 280 | max_space = space |
|
283 | 281 | until stack.empty? |
|
284 | 282 | space, commit = stack.pop |
|
285 | 283 | commit[:space] = space if commit[:space].nil? |
|
286 | 284 | space -= 1 |
|
287 | 285 | commit[:parent_scmids].each_with_index do |parent_scmid, parent_index| |
|
288 | 286 | parent_commit = commits_by_scmid[parent_scmid] |
|
289 | 287 | if parent_commit and parent_commit[:space].nil? |
|
290 | 288 | stack.unshift [space += 1, parent_commit] |
|
291 | 289 | end |
|
292 | 290 | end |
|
293 | 291 | max_space = space if max_space < space |
|
294 | 292 | end |
|
295 | 293 | max_space |
|
296 | 294 | end |
|
297 | 295 | end |
General Comments 0
You need to be logged in to leave comments.
Login now