Commit ccc712b1 authored by Sato Hiroyuki's avatar Sato Hiroyuki

Refacor: removing the times array, because that is same with @commits array.

parent 8c5003cf
...@@ -23,13 +23,21 @@ module Network ...@@ -23,13 +23,21 @@ module Network
# Get commits from repository # Get commits from repository
# #
def collect_commits def collect_commits
@commits = Grit::Commit.find_all(@repo, nil, {date_order: true, max_count: self.class.max_count, skip: to_commit}).dup
# Decorate with app/model/network/commit.rb
refs_cache = build_refs_cache refs_cache = build_refs_cache
@commits.map! { |commit| Network::Commit.new(commit, refs_cache[commit.id]) }
@commits Grit::Commit.find_all(
@repo,
nil,
{
date_order: true,
max_count: self.class.max_count,
skip: count_to_display_commit_in_center
}
)
.map do |commit|
# Decorate with app/model/network/commit.rb
Network::Commit.new(commit, refs_cache[commit.id])
end
end end
# Method is adding time and space on the # Method is adding time and space on the
...@@ -40,14 +48,13 @@ module Network ...@@ -40,14 +48,13 @@ module Network
# #
# @return [Array<TimeDate>] list of commit dates corelated with time on commits # @return [Array<TimeDate>] list of commit dates corelated with time on commits
def index_commits def index_commits
days, times = [], [] days = []
map = {} map = {}
commits.reverse.each_with_index do |c,i| @commits.reverse.each_with_index do |c,i|
c.time = i c.time = i
days[i] = c.committed_date days[i] = c.committed_date
map[c.id] = c map[c.id] = c
times[i] = c
end end
@_reserved = {} @_reserved = {}
...@@ -62,17 +69,16 @@ module Network ...@@ -62,17 +69,16 @@ module Network
end end
# find parent spaces for not overlap lines # find parent spaces for not overlap lines
times.each do |c| @commits.each do |c|
c.parent_spaces.concat(find_free_parent_spaces(c, map, times)) c.parent_spaces.concat(find_free_parent_spaces(c, map))
end end
days days
end end
# Skip count that the target commit is displayed in center. # Skip count that the target commit is displayed in center.
def to_commit def count_to_display_commit_in_center
commits = Grit::Commit.find_all(@repo, nil, {date_order: true}) commit_index = Grit::Commit.find_all(@repo, nil, {date_order: true}).index do |c|
commit_index = commits.index do |c|
c.id == @commit.id c.id == @commit.id
end end
...@@ -85,7 +91,7 @@ module Network ...@@ -85,7 +91,7 @@ module Network
end end
def commits_sort_by_ref def commits_sort_by_ref
commits.sort do |a,b| @commits.sort do |a,b|
if include_ref?(a) if include_ref?(a)
-1 -1
elsif include_ref?(b) elsif include_ref?(b)
...@@ -108,7 +114,7 @@ module Network ...@@ -108,7 +114,7 @@ module Network
heads.include?(@ref) heads.include?(@ref)
end end
def find_free_parent_spaces(commit, map, times) def find_free_parent_spaces(commit, map)
spaces = [] spaces = []
commit.parents.each do |p| commit.parents.each do |p|
...@@ -122,9 +128,9 @@ module Network ...@@ -122,9 +128,9 @@ module Network
end end
space = if commit.space >= parent.space then space = if commit.space >= parent.space then
find_free_parent_space(range, parent.space, -1, commit.space, times) find_free_parent_space(range, parent.space, -1, commit.space)
else else
find_free_parent_space(range, commit.space, -1, parent.space, times) find_free_parent_space(range, commit.space, -1, parent.space)
end end
mark_reserved(range, space) mark_reserved(range, space)
...@@ -135,19 +141,19 @@ module Network ...@@ -135,19 +141,19 @@ module Network
spaces spaces
end end
def find_free_parent_space(range, space_base, space_step, space_default, times) def find_free_parent_space(range, space_base, space_step, space_default)
if is_overlap?(range, times, space_default) then if is_overlap?(range, space_default) then
find_free_space(range, space_step, space_base, space_default) find_free_space(range, space_step, space_base, space_default)
else else
space_default space_default
end end
end end
def is_overlap?(range, times, overlap_space) def is_overlap?(range, overlap_space)
range.each do |i| range.each do |i|
if i != range.first && if i != range.first &&
i != range.last && i != range.last &&
times[i].spaces.include?(overlap_space) then @commits[reversed_index(i)].spaces.include?(overlap_space) then
return true; return true;
end end
...@@ -282,5 +288,9 @@ module Network ...@@ -282,5 +288,9 @@ module Network
end end
refs_cache refs_cache
end end
def reversed_index(index)
-index - 1
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment