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 | 98 | if leaves.empty? |
99 | 99 | return |
100 | 100 | end |
101 | - space = find_free_space(leaves.last.time..leaves.first.time) | |
101 | + space = find_free_space(leaves, map) | |
102 | 102 | leaves.each{|l| l.space = space} |
103 | 103 | # and mark it as reserved |
104 | 104 | min_time = leaves.last.time |
... | ... | @@ -120,7 +120,7 @@ module Gitlab |
120 | 120 | |
121 | 121 | # Visit branching chains |
122 | 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 | 124 | for p in parents |
125 | 125 | place_chain(map[p.id], map, l.time) |
126 | 126 | end |
... | ... | @@ -133,18 +133,29 @@ module Gitlab |
133 | 133 | end |
134 | 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 | 138 | reserved = [] |
138 | 139 | for day in time_range |
139 | 140 | reserved += @_reserved[day] |
140 | 141 | end |
141 | - space = 1 | |
142 | + space = base_space(leaves, map) | |
142 | 143 | while reserved.include? space do |
143 | 144 | space += 1 |
144 | 145 | end |
145 | 146 | space |
146 | 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 | 159 | # Takes most left subtree branch of commits |
149 | 160 | # which don't have space mark yet. |
150 | 161 | # |
... | ... | @@ -157,13 +168,13 @@ module Gitlab |
157 | 168 | leaves.push(commit) if commit.space.zero? |
158 | 169 | |
159 | 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 | 178 | leaves.push(commit) |
168 | 179 | end |
169 | 180 | end | ... | ... |