Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
79cd1ca3
Commit
79cd1ca3
authored
Mar 07, 2013
by
Sato Hiroyuki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: change the map hash from a local variable to private variable.
parent
ccc712b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
34 deletions
+31
-34
app/models/network/graph.rb
app/models/network/graph.rb
+31
-34
No files found.
app/models/network/graph.rb
View file @
79cd1ca3
...
...
@@ -44,33 +44,31 @@ module Network
# list of commits. As well as returns date list
# corelated with time set on commits.
#
# @param [Array<Graph::Commit>] commits to index
#
# @return [Array<TimeDate>] list of commit dates corelated with time on commits
def
index_commits
days
=
[]
map
=
{}
@
map
=
{}
@commits
.
reverse
.
each_with_index
do
|
c
,
i
|
c
.
time
=
i
days
[
i
]
=
c
.
committed_date
map
[
c
.
id
]
=
c
@
map
[
c
.
id
]
=
c
end
@
_
reserved
=
{}
@reserved
=
{}
days
.
each_index
do
|
i
|
@
_
reserved
[
i
]
=
[]
@reserved
[
i
]
=
[]
end
commits_sort_by_ref
.
each
do
|
commit
|
if
map
.
include?
commit
.
id
then
place_chain
(
map
[
commit
.
id
],
map
)
if
@
map
.
include?
commit
.
id
then
place_chain
(
commit
)
end
end
# find parent spaces for not overlap lines
@commits
.
each
do
|
c
|
c
.
parent_spaces
.
concat
(
find_free_parent_spaces
(
c
,
map
))
c
.
parent_spaces
.
concat
(
find_free_parent_spaces
(
c
))
end
days
...
...
@@ -114,12 +112,12 @@ module Network
heads
.
include?
(
@ref
)
end
def
find_free_parent_spaces
(
commit
,
map
)
def
find_free_parent_spaces
(
commit
)
spaces
=
[]
commit
.
parents
.
each
do
|
p
|
if
map
.
include?
(
p
.
id
)
then
parent
=
map
[
p
.
id
]
if
@
map
.
include?
(
p
.
id
)
then
parent
=
@
map
[
p
.
id
]
range
=
if
commit
.
time
<
parent
.
time
then
commit
.
time
..
parent
.
time
...
...
@@ -164,23 +162,22 @@ module Network
# Add space mark on commit and its parents
#
# @param [Graph::Commit] the commit object.
# @param [Hash<String,Graph::Commit>] map of commits
def
place_chain
(
commit
,
map
,
parent_time
=
nil
)
leaves
=
take_left_leaves
(
commit
,
map
)
# @param [::Commit] the commit object.
def
place_chain
(
commit
,
parent_time
=
nil
)
leaves
=
take_left_leaves
(
commit
)
if
leaves
.
empty?
return
end
time_range
=
leaves
.
last
.
time
..
leaves
.
first
.
time
space_base
=
get_space_base
(
leaves
,
map
)
space_base
=
get_space_base
(
leaves
)
space
=
find_free_space
(
time_range
,
2
,
space_base
)
leaves
.
each
do
|
l
|
l
.
spaces
<<
space
# Also add space to parent
l
.
parents
.
each
do
|
p
|
if
map
.
include?
(
p
.
id
)
parent
=
map
[
p
.
id
]
if
@
map
.
include?
(
p
.
id
)
parent
=
@
map
[
p
.
id
]
if
parent
.
space
>
0
parent
.
spaces
<<
space
end
...
...
@@ -192,8 +189,8 @@ module Network
min_time
=
leaves
.
last
.
time
parents
=
leaves
.
last
.
parents
.
collect
parents
.
each
do
|
p
|
if
map
.
include?
p
.
id
parent
=
map
[
p
.
id
]
if
@
map
.
include?
p
.
id
parent
=
@
map
[
p
.
id
]
if
parent
.
time
<
min_time
min_time
=
parent
.
time
end
...
...
@@ -209,19 +206,19 @@ module Network
# Visit branching chains
leaves
.
each
do
|
l
|
parents
=
l
.
parents
.
collect
.
select
{
|
p
|
map
.
include?
p
.
id
and
map
[
p
.
id
].
space
.
zero?
}
parents
=
l
.
parents
.
collect
.
select
{
|
p
|
@map
.
include?
p
.
id
and
@
map
[
p
.
id
].
space
.
zero?
}
for
p
in
parents
place_chain
(
map
[
p
.
id
],
ma
p
,
l
.
time
)
place_chain
(
p
,
l
.
time
)
end
end
end
def
get_space_base
(
leaves
,
map
)
def
get_space_base
(
leaves
)
space_base
=
1
if
leaves
.
last
.
parents
.
size
>
0
first_parent
=
leaves
.
last
.
parents
.
first
if
map
.
include?
(
first_parent
.
id
)
first_p
=
map
[
first_parent
.
id
]
if
@
map
.
include?
(
first_parent
.
id
)
first_p
=
@
map
[
first_parent
.
id
]
if
first_p
.
space
>
0
space_base
=
first_p
.
space
end
...
...
@@ -232,7 +229,7 @@ module Network
def
mark_reserved
(
time_range
,
space
)
for
day
in
time_range
@
_
reserved
[
day
].
push
(
space
)
@reserved
[
day
].
push
(
space
)
end
end
...
...
@@ -241,7 +238,7 @@ module Network
reserved
=
[]
for
day
in
time_range
reserved
+=
@
_
reserved
[
day
]
reserved
+=
@reserved
[
day
]
end
reserved
.
uniq!
...
...
@@ -260,19 +257,19 @@ module Network
# Takes most left subtree branch of commits
# which don't have space mark yet.
#
# @param [Graph::Commit] the commit object.
# @param [Hash<String,Graph::Commit>] map of commits
# @param [::Commit] the commit object.
#
# @return [Array<Graph::Commit>] list of branch commits
def
take_left_leaves
(
commit
,
map
)
# @return [Array<Network::Commit>] list of branch commits
def
take_left_leaves
(
raw_commit
)
commit
=
@map
[
raw_commit
.
id
]
leaves
=
[]
leaves
.
push
(
commit
)
if
commit
.
space
.
zero?
while
true
return
leaves
if
commit
.
parents
.
count
.
zero?
return
leaves
unless
map
.
include?
commit
.
parents
.
first
.
id
return
leaves
unless
@
map
.
include?
commit
.
parents
.
first
.
id
commit
=
map
[
commit
.
parents
.
first
.
id
]
commit
=
@
map
[
commit
.
parents
.
first
.
id
]
return
leaves
unless
commit
.
space
.
zero?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment