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