@@ -252,16 +252,13 module RepositoriesHelper | |||
|
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, |
@@ -270,38 +267,28 module RepositoriesHelper | |||
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now