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