Commit 5fd830f01c483dcccd8312caf289d5d03e7f389c
1 parent
743073ce
Exists in
master
and in
4 other branches
Improve network-graph
Showing
1 changed file
with
20 additions
and
9 deletions
Show diff stats
lib/gitlab/graph/json_builder.rb
| @@ -98,7 +98,7 @@ module Gitlab | @@ -98,7 +98,7 @@ module Gitlab | ||
| 98 | if leaves.empty? | 98 | if leaves.empty? |
| 99 | return | 99 | return |
| 100 | end | 100 | end |
| 101 | - space = find_free_space(leaves.last.time..leaves.first.time) | 101 | + space = find_free_space(leaves, map) |
| 102 | leaves.each{|l| l.space = space} | 102 | leaves.each{|l| l.space = space} |
| 103 | # and mark it as reserved | 103 | # and mark it as reserved |
| 104 | min_time = leaves.last.time | 104 | min_time = leaves.last.time |
| @@ -120,7 +120,7 @@ module Gitlab | @@ -120,7 +120,7 @@ module Gitlab | ||
| 120 | 120 | ||
| 121 | # Visit branching chains | 121 | # Visit branching chains |
| 122 | leaves.each do |l| | 122 | leaves.each do |l| |
| 123 | - parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space == 0} | 123 | + parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space.zero?} |
| 124 | for p in parents | 124 | for p in parents |
| 125 | place_chain(map[p.id], map, l.time) | 125 | place_chain(map[p.id], map, l.time) |
| 126 | end | 126 | end |
| @@ -133,18 +133,29 @@ module Gitlab | @@ -133,18 +133,29 @@ module Gitlab | ||
| 133 | end | 133 | end |
| 134 | end | 134 | end |
| 135 | 135 | ||
| 136 | - def find_free_space(time_range) | 136 | + def find_free_space(leaves, map) |
| 137 | + time_range = leaves.last.time..leaves.first.time | ||
| 137 | reserved = [] | 138 | reserved = [] |
| 138 | for day in time_range | 139 | for day in time_range |
| 139 | reserved += @_reserved[day] | 140 | reserved += @_reserved[day] |
| 140 | end | 141 | end |
| 141 | - space = 1 | 142 | + space = base_space(leaves, map) |
| 142 | while reserved.include? space do | 143 | while reserved.include? space do |
| 143 | space += 1 | 144 | space += 1 |
| 144 | end | 145 | end |
| 145 | space | 146 | space |
| 146 | end | 147 | end |
| 147 | 148 | ||
| 149 | + def base_space(leaves, map) | ||
| 150 | + parents = [] | ||
| 151 | + leaves.each do |l| | ||
| 152 | + parents.concat l.parents.collect.select{|p| map.include? p.id and map[p.id].space.nonzero?} | ||
| 153 | + end | ||
| 154 | + | ||
| 155 | + space = parents.map{|p| map[p.id].space}.max || 0 | ||
| 156 | + space += 1 | ||
| 157 | + end | ||
| 158 | + | ||
| 148 | # Takes most left subtree branch of commits | 159 | # Takes most left subtree branch of commits |
| 149 | # which don't have space mark yet. | 160 | # which don't have space mark yet. |
| 150 | # | 161 | # |
| @@ -157,13 +168,13 @@ module Gitlab | @@ -157,13 +168,13 @@ module Gitlab | ||
| 157 | leaves.push(commit) if commit.space.zero? | 168 | leaves.push(commit) if commit.space.zero? |
| 158 | 169 | ||
| 159 | while true | 170 | while true |
| 160 | - parent = commit.parents.collect.select do |p| | ||
| 161 | - map.include? p.id and map[p.id].space == 0 | ||
| 162 | - end | 171 | + return leaves if commit.parents.count.zero? |
| 172 | + return leaves unless map.include? commit.parents.first.id | ||
| 173 | + | ||
| 174 | + commit = map[commit.parents.first.id] | ||
| 163 | 175 | ||
| 164 | - return leaves if parent.count.zero? | 176 | + return leaves unless commit.space.zero? |
| 165 | 177 | ||
| 166 | - commit = map[parent.first.id] | ||
| 167 | leaves.push(commit) | 178 | leaves.push(commit) |
| 168 | end | 179 | end |
| 169 | end | 180 | end |