BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d8a40d8c
Commit
d8a40d8c
authored
Feb 26, 2013
by
Sato Hiroyuki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move graph module from lib or vendor directory to app directory.
Because not autoloading lib directory at development mode.
parent
c9b1df12
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
239 additions
and
245 deletions
+239
-245
branch-graph.js
app/assets/javascripts/branch-graph.js
+0
-0
graph_controller.rb
app/controllers/graph_controller.rb
+1
-1
projects_controller.rb
app/controllers/projects_controller.rb
+0
-2
commit.rb
app/models/graph/commit.rb
+37
-39
json_builder.rb
app/models/graph/json_builder.rb
+201
-203
No files found.
vendor
/assets/javascripts/branch-graph.js
→
app
/assets/javascripts/branch-graph.js
View file @
d8a40d8c
File moved
app/controllers/graph_controller.rb
View file @
d8a40d8c
...
...
@@ -20,7 +20,7 @@ class GraphController < ProjectResourceController
respond_to
do
|
format
|
format
.
html
format
.
json
do
graph
=
G
itlab
::
G
raph
::
JsonBuilder
.
new
(
project
,
@ref
,
@commit
)
graph
=
Graph
::
JsonBuilder
.
new
(
project
,
@ref
,
@commit
)
render
:json
=>
graph
.
to_json
end
end
...
...
app/controllers/projects_controller.rb
View file @
d8a40d8c
require
Rails
.
root
.
join
(
'lib'
,
'gitlab'
,
'graph'
,
'json_builder'
)
class
ProjectsController
<
ProjectResourceController
skip_before_filter
:project
,
only:
[
:new
,
:create
]
skip_before_filter
:repository
,
only:
[
:new
,
:create
]
...
...
lib/gitlab
/graph/commit.rb
→
app/models
/graph/commit.rb
View file @
d8a40d8c
require
"grit"
module
Gitlab
module
Graph
class
Commit
include
ActionView
::
Helpers
::
TagHelper
module
Graph
class
Commit
include
ActionView
::
Helpers
::
TagHelper
attr_accessor
:time
,
:space
,
:refs
,
:parent_spaces
attr_accessor
:time
,
:space
,
:refs
,
:parent_spaces
def
initialize
(
commit
)
@_commit
=
commit
@time
=
-
1
@space
=
0
@parent_spaces
=
[]
end
def
initialize
(
commit
)
@_commit
=
commit
@time
=
-
1
@space
=
0
@parent_spaces
=
[]
end
def
method_missing
(
m
,
*
args
,
&
block
)
@_commit
.
send
(
m
,
*
args
,
&
block
)
end
def
method_missing
(
m
,
*
args
,
&
block
)
@_commit
.
send
(
m
,
*
args
,
&
block
)
end
def
to_graph_hash
h
=
{}
h
[
:parents
]
=
self
.
parents
.
collect
do
|
p
|
[
p
.
id
,
0
,
0
]
end
h
[
:author
]
=
{
name:
author
.
name
,
email:
author
.
email
}
h
[
:time
]
=
time
h
[
:space
]
=
space
h
[
:parent_spaces
]
=
parent_spaces
h
[
:refs
]
=
refs
.
collect
{
|
r
|
r
.
name
}.
join
(
" "
)
unless
refs
.
nil?
h
[
:id
]
=
sha
h
[
:date
]
=
date
h
[
:message
]
=
message
h
def
to_graph_hash
h
=
{}
h
[
:parents
]
=
self
.
parents
.
collect
do
|
p
|
[
p
.
id
,
0
,
0
]
end
h
[
:author
]
=
{
name:
author
.
name
,
email:
author
.
email
}
h
[
:time
]
=
time
h
[
:space
]
=
space
h
[
:parent_spaces
]
=
parent_spaces
h
[
:refs
]
=
refs
.
collect
{
|
r
|
r
.
name
}.
join
(
" "
)
unless
refs
.
nil?
h
[
:id
]
=
sha
h
[
:date
]
=
date
h
[
:message
]
=
message
h
end
def
add_refs
(
ref_cache
,
repo
)
if
ref_cache
.
empty?
repo
.
refs
.
each
do
|
ref
|
ref_cache
[
ref
.
commit
.
id
]
||=
[]
ref_cache
[
ref
.
commit
.
id
]
<<
ref
end
def
add_refs
(
ref_cache
,
repo
)
if
ref_cache
.
empty?
repo
.
refs
.
each
do
|
ref
|
ref_cache
[
ref
.
commit
.
id
]
||=
[]
ref_cache
[
ref
.
commit
.
id
]
<<
ref
end
@refs
=
ref_cache
[
@_commit
.
id
]
if
ref_cache
.
include?
(
@_commit
.
id
)
@refs
||=
[]
end
@refs
=
ref_cache
[
@_commit
.
id
]
if
ref_cache
.
include?
(
@_commit
.
id
)
@refs
||=
[]
end
end
end
lib/gitlab
/graph/json_builder.rb
→
app/models
/graph/json_builder.rb
View file @
d8a40d8c
require
"grit"
module
Gitlab
module
Graph
class
JsonBuilder
attr_accessor
:days
,
:commits
,
:ref_cache
,
:repo
module
Graph
class
JsonBuilder
attr_accessor
:days
,
:commits
,
:ref_cache
,
:repo
def
self
.
max_count
@max_count
||=
650
end
def
self
.
max_count
@max_count
||=
650
end
def
initialize
project
,
ref
,
commit
@project
=
project
@ref
=
ref
@commit
=
commit
@repo
=
project
.
repo
@ref_cache
=
{}
def
initialize
project
,
ref
,
commit
@project
=
project
@ref
=
ref
@commit
=
commit
@repo
=
project
.
repo
@ref_cache
=
{}
@commits
=
collect_commits
@days
=
index_commits
end
@commits
=
collect_commits
@days
=
index_commits
end
def
to_json
(
*
args
)
{
days:
@days
.
compact
.
map
{
|
d
|
[
d
.
day
,
d
.
strftime
(
"%b"
)]
},
commits:
@commits
.
map
(
&
:to_graph_hash
)
}.
to_json
(
*
args
)
end
def
to_json
(
*
args
)
{
days:
@days
.
compact
.
map
{
|
d
|
[
d
.
day
,
d
.
strftime
(
"%b"
)]
},
commits:
@commits
.
map
(
&
:to_graph_hash
)
}.
to_json
(
*
args
)
end
protected
protected
# Get commits from repository
#
def
collect_commits
# Get commits from repository
#
def
collect_commits
@commits
=
Grit
::
Commit
.
find_all
(
repo
,
nil
,
{
topo_order:
true
,
max_count:
self
.
class
.
max_count
,
skip:
to_commit
}).
dup
@commits
=
Grit
::
Commit
.
find_all
(
repo
,
nil
,
{
topo_order:
true
,
max_count:
self
.
class
.
max_count
,
skip:
to_commit
}).
dup
# Decorate with app/models/commit.rb
@commits
.
map!
{
|
commit
|
::
Commit
.
new
(
commit
)
}
# Decorate with app/models/commit.rb
@commits
.
map!
{
|
commit
|
Commit
.
new
(
commit
)
}
# Decorate with lib/gitlab/graph/commit.rb
@commits
.
map!
{
|
commit
|
Gitlab
::
Graph
::
Commit
.
new
(
commit
)
}
# Decorate with lib/gitlab/graph/commit.rb
@commits
.
map!
{
|
commit
|
Graph
::
Commit
.
new
(
commit
)
}
# add refs to each commit
@commits
.
each
{
|
commit
|
commit
.
add_refs
(
ref_cache
,
repo
)
}
# add refs to each commit
@commits
.
each
{
|
commit
|
commit
.
add_refs
(
ref_cache
,
repo
)
}
@commits
end
@commits
# Method is adding time and space on the
# 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
,
times
=
[],
[]
map
=
{}
commits
.
reverse
.
each_with_index
do
|
c
,
i
|
c
.
time
=
i
days
[
i
]
=
c
.
committed_date
map
[
c
.
id
]
=
c
times
[
i
]
=
c
end
# Method is adding time and space on the
# 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
,
times
=
[],
[]
map
=
{}
commits
.
reverse
.
each_with_index
do
|
c
,
i
|
c
.
time
=
i
days
[
i
]
=
c
.
committed_date
map
[
c
.
id
]
=
c
times
[
i
]
=
c
end
@_reserved
=
{}
days
.
each_index
do
|
i
|
@_reserved
[
i
]
=
[]
end
@_reserved
=
{}
days
.
each_index
do
|
i
|
@_reserved
[
i
]
=
[]
commits_sort_by_ref
.
each
do
|
commit
|
if
map
.
include?
commit
.
id
then
place_chain
(
map
[
commit
.
id
],
map
)
end
end
commits_sort_by_ref
.
each
do
|
commit
|
if
map
.
include?
commit
.
id
then
place_chain
(
map
[
commit
.
id
],
map
)
end
end
# find parent spaces for not overlap lines
times
.
each
do
|
c
|
c
.
parent_spaces
.
concat
(
find_free_parent_spaces
(
c
,
map
,
times
))
end
# find parent spaces for not overlap lines
times
.
each
do
|
c
|
c
.
parent_spaces
.
concat
(
find_free_parent_spaces
(
c
,
map
,
times
))
end
days
end
days
# Skip count that the target commit is displayed in center.
def
to_commit
commits
=
Grit
::
Commit
.
find_all
(
repo
,
nil
,
{
topo_order:
true
})
commit_index
=
commits
.
index
do
|
c
|
c
.
id
==
@commit
.
id
end
# Skip count that the target commit is displayed in center.
def
to_commit
commits
=
Grit
::
Commit
.
find_all
(
repo
,
nil
,
{
topo_order:
true
})
commit_index
=
commits
.
index
do
|
c
|
c
.
id
==
@commit
.
id
end
if
commit_index
&&
(
self
.
class
.
max_count
/
2
<
commit_index
)
then
# get max index that commit is displayed in the center.
commit_index
-
self
.
class
.
max_count
/
2
else
0
end
end
if
commit_index
&&
(
self
.
class
.
max_count
/
2
<
commit_index
)
then
# get max index that commit is displayed in the center.
commit_index
-
self
.
class
.
max_count
/
2
def
commits_sort_by_ref
commits
.
sort
do
|
a
,
b
|
if
include_ref?
(
a
)
-
1
elsif
include_ref?
(
b
)
1
else
0
b
.
committed_date
<=>
a
.
committed_date
end
end
end
def
commits_sort_by_ref
commits
.
sort
do
|
a
,
b
|
if
include_ref?
(
a
)
-
1
elsif
include_ref?
(
b
)
1
else
b
.
committed_date
<=>
a
.
committed_date
end
end
def
include_ref?
(
commit
)
heads
=
commit
.
refs
.
select
do
|
ref
|
ref
.
is_a?
(
Grit
::
Head
)
or
ref
.
is_a?
(
Grit
::
Remote
)
or
ref
.
is_a?
(
Grit
::
Tag
)
end
def
include_ref?
(
commit
)
heads
=
commit
.
refs
.
select
do
|
ref
|
ref
.
is_a?
(
Grit
::
Head
)
or
ref
.
is_a?
(
Grit
::
Remote
)
or
ref
.
is_a?
(
Grit
::
Tag
)
end
heads
.
map!
do
|
head
|
head
.
name
end
heads
.
include?
(
@ref
)
heads
.
map!
do
|
head
|
head
.
name
end
def
find_free_parent_spaces
(
commit
,
map
,
times
)
spaces
=
[]
heads
.
include?
(
@ref
)
end
commit
.
parents
.
each
do
|
p
|
if
map
.
include?
(
p
.
id
)
then
parent
=
map
[
p
.
id
]
def
find_free_parent_spaces
(
commit
,
map
,
times
)
spaces
=
[]
range
=
if
commit
.
time
<
parent
.
time
then
commit
.
time
..
parent
.
time
else
parent
.
time
..
commit
.
time
end
commit
.
parents
.
each
do
|
p
|
if
map
.
include?
(
p
.
id
)
then
parent
=
map
[
p
.
id
]
space
=
if
commit
.
space
>=
parent
.
spac
e
then
find_free_parent_space
(
range
,
parent
.
space
,
1
,
commit
.
space
,
times
)
else
find_free_parent_space
(
range
,
parent
.
space
,
-
1
,
parent
.
space
,
times
)
end
range
=
if
commit
.
time
<
parent
.
tim
e
then
commit
.
time
..
parent
.
time
else
parent
.
time
..
commit
.
time
end
mark_reserved
(
range
,
space
)
spaces
<<
space
end
end
space
=
if
commit
.
space
>=
parent
.
space
then
find_free_parent_space
(
range
,
parent
.
space
,
1
,
commit
.
space
,
times
)
else
find_free_parent_space
(
range
,
parent
.
space
,
-
1
,
parent
.
space
,
times
)
end
spaces
mark_reserved
(
range
,
space
)
spaces
<<
space
end
end
def
find_free_parent_space
(
range
,
space_base
,
space_step
,
space_default
,
times
)
if
is_overlap?
(
range
,
times
,
space_default
)
then
find_free_space
(
range
,
space_base
,
space_step
)
else
space_default
end
spaces
end
def
find_free_parent_space
(
range
,
space_base
,
space_step
,
space_default
,
times
)
if
is_overlap?
(
range
,
times
,
space_default
)
then
find_free_space
(
range
,
space_base
,
space_step
)
else
space_default
end
end
def
is_overlap?
(
range
,
times
,
overlap_space
)
range
.
each
do
|
i
|
if
i
!=
range
.
first
&&
i
!=
range
.
last
&&
times
[
i
].
space
==
overlap_space
then
def
is_overlap?
(
range
,
times
,
overlap_space
)
range
.
each
do
|
i
|
if
i
!=
range
.
first
&&
i
!=
range
.
last
&&
times
[
i
].
space
==
overlap_space
then
return
true
;
end
return
true
;
end
false
end
# 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
)
if
leaves
.
empty?
return
end
# and mark it as reserved
min_time
=
leaves
.
last
.
time
max_space
=
1
parents
=
leaves
.
last
.
parents
.
collect
parents
.
each
do
|
p
|
if
map
.
include?
p
.
id
parent
=
map
[
p
.
id
]
if
parent
.
time
<
min_time
min_time
=
parent
.
time
end
if
max_space
<
parent
.
space
then
max_space
=
parent
.
space
end
false
end
# 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
)
if
leaves
.
empty?
return
end
# and mark it as reserved
min_time
=
leaves
.
last
.
time
max_space
=
1
parents
=
leaves
.
last
.
parents
.
collect
parents
.
each
do
|
p
|
if
map
.
include?
p
.
id
parent
=
map
[
p
.
id
]
if
parent
.
time
<
min_time
min_time
=
parent
.
time
end
if
max_space
<
parent
.
space
then
max_space
=
parent
.
space
end
end
if
parent_time
.
nil?
max_time
=
leaves
.
first
.
time
else
max_time
=
parent_time
-
1
end
end
if
parent_time
.
nil?
max_time
=
leaves
.
first
.
time
else
max_time
=
parent_time
-
1
end
time_range
=
leaves
.
last
.
time
..
leaves
.
first
.
time
space
=
find_free_space
(
time_range
,
max_space
,
2
)
leaves
.
each
{
|
l
|
l
.
space
=
space
}
time_range
=
leaves
.
last
.
time
..
leaves
.
first
.
time
space
=
find_free_space
(
time_range
,
max_space
,
2
)
leaves
.
each
{
|
l
|
l
.
space
=
space
}
mark_reserved
(
min_time
..
max_time
,
space
)
mark_reserved
(
min_time
..
max_time
,
space
)
# Visit branching chains
leaves
.
each
do
|
l
|
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
],
map
,
l
.
time
)
end
# Visit branching chains
leaves
.
each
do
|
l
|
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
],
map
,
l
.
time
)
end
end
end
def
mark_reserved
(
time_range
,
space
)
for
day
in
time_range
@_reserved
[
day
].
push
(
space
)
end
def
mark_reserved
(
time_range
,
space
)
for
day
in
time_range
@_reserved
[
day
].
push
(
space
)
end
end
def
find_free_space
(
time_range
,
space_base
,
space_step
)
reserved
=
[]
for
day
in
time_range
reserved
+=
@_reserved
[
day
]
end
reserved
.
uniq!
space
=
space_base
while
reserved
.
include?
(
space
)
do
space
+=
space_step
if
space
<=
0
then
space_step
*=
-
1
space
=
space_base
+
space_step
end
def
find_free_space
(
time_range
,
space_base
,
space_step
)
reserved
=
[]
for
day
in
time_range
reserved
+=
@_reserved
[
day
]
end
reserved
.
uniq!
space
=
space_base
while
reserved
.
include?
(
space
)
do
space
+=
space_step
if
space
<=
0
then
space_step
*=
-
1
space
=
space_base
+
space_step
end
space
end
# 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
#
# @return [Array<Graph::Commit>] list of branch commits
def
take_left_leaves
(
commit
,
map
)
leaves
=
[]
leaves
.
push
(
commit
)
if
commit
.
space
.
zero?
space
end
while
true
return
leaves
if
commit
.
parents
.
count
.
zero?
return
leaves
unless
map
.
include?
commit
.
parents
.
first
.
id
# 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
#
# @return [Array<Graph::Commit>] list of branch commits
def
take_left_leaves
(
commit
,
map
)
leaves
=
[]
leaves
.
push
(
commit
)
if
commit
.
space
.
zero?
commit
=
map
[
commit
.
parents
.
first
.
id
]
while
true
return
leaves
if
commit
.
parents
.
count
.
zero?
return
leaves
unless
map
.
include?
commit
.
parents
.
first
.
id
return
leaves
unless
commit
.
space
.
zero?
commit
=
map
[
commit
.
parents
.
first
.
id
]
leaves
.
push
(
commit
)
end
return
leaves
unless
commit
.
space
.
zero?
leaves
.
push
(
commit
)
end
end
end
...
...
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