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