Commit ccc712b1983f49216fc85deb61a7e5efd7790936

Authored by Sato Hiroyuki
1 parent 8c5003cf

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

Showing 1 changed file with 31 additions and 21 deletions   Show diff stats
app/models/network/graph.rb
... ... @@ -23,13 +23,21 @@ module Network
23 23 # Get commits from repository
24 24 #
25 25 def collect_commits
26   - @commits = Grit::Commit.find_all(@repo, nil, {date_order: true, max_count: self.class.max_count, skip: to_commit}).dup
27   -
28   - # Decorate with app/model/network/commit.rb
29 26 refs_cache = build_refs_cache
30   - @commits.map! { |commit| Network::Commit.new(commit, refs_cache[commit.id]) }
31 27  
32   - @commits
  28 + Grit::Commit.find_all(
  29 + @repo,
  30 + nil,
  31 + {
  32 + date_order: true,
  33 + max_count: self.class.max_count,
  34 + skip: count_to_display_commit_in_center
  35 + }
  36 + )
  37 + .map do |commit|
  38 + # Decorate with app/model/network/commit.rb
  39 + Network::Commit.new(commit, refs_cache[commit.id])
  40 + end
33 41 end
34 42  
35 43 # Method is adding time and space on the
... ... @@ -40,14 +48,13 @@ module Network
40 48 #
41 49 # @return [Array<TimeDate>] list of commit dates corelated with time on commits
42 50 def index_commits
43   - days, times = [], []
  51 + days = []
44 52 map = {}
45 53  
46   - commits.reverse.each_with_index do |c,i|
  54 + @commits.reverse.each_with_index do |c,i|
47 55 c.time = i
48 56 days[i] = c.committed_date
49 57 map[c.id] = c
50   - times[i] = c
51 58 end
52 59  
53 60 @_reserved = {}
... ... @@ -62,17 +69,16 @@ module Network
62 69 end
63 70  
64 71 # find parent spaces for not overlap lines
65   - times.each do |c|
66   - c.parent_spaces.concat(find_free_parent_spaces(c, map, times))
  72 + @commits.each do |c|
  73 + c.parent_spaces.concat(find_free_parent_spaces(c, map))
67 74 end
68 75  
69 76 days
70 77 end
71 78  
72 79 # Skip count that the target commit is displayed in center.
73   - def to_commit
74   - commits = Grit::Commit.find_all(@repo, nil, {date_order: true})
75   - commit_index = commits.index do |c|
  80 + def count_to_display_commit_in_center
  81 + commit_index = Grit::Commit.find_all(@repo, nil, {date_order: true}).index do |c|
76 82 c.id == @commit.id
77 83 end
78 84  
... ... @@ -85,7 +91,7 @@ module Network
85 91 end
86 92  
87 93 def commits_sort_by_ref
88   - commits.sort do |a,b|
  94 + @commits.sort do |a,b|
89 95 if include_ref?(a)
90 96 -1
91 97 elsif include_ref?(b)
... ... @@ -108,7 +114,7 @@ module Network
108 114 heads.include?(@ref)
109 115 end
110 116  
111   - def find_free_parent_spaces(commit, map, times)
  117 + def find_free_parent_spaces(commit, map)
112 118 spaces = []
113 119  
114 120 commit.parents.each do |p|
... ... @@ -122,9 +128,9 @@ module Network
122 128 end
123 129  
124 130 space = if commit.space >= parent.space then
125   - find_free_parent_space(range, parent.space, -1, commit.space, times)
  131 + find_free_parent_space(range, parent.space, -1, commit.space)
126 132 else
127   - find_free_parent_space(range, commit.space, -1, parent.space, times)
  133 + find_free_parent_space(range, commit.space, -1, parent.space)
128 134 end
129 135  
130 136 mark_reserved(range, space)
... ... @@ -135,19 +141,19 @@ module Network
135 141 spaces
136 142 end
137 143  
138   - def find_free_parent_space(range, space_base, space_step, space_default, times)
139   - if is_overlap?(range, times, space_default) then
  144 + def find_free_parent_space(range, space_base, space_step, space_default)
  145 + if is_overlap?(range, space_default) then
140 146 find_free_space(range, space_step, space_base, space_default)
141 147 else
142 148 space_default
143 149 end
144 150 end
145 151  
146   - def is_overlap?(range, times, overlap_space)
  152 + def is_overlap?(range, overlap_space)
147 153 range.each do |i|
148 154 if i != range.first &&
149 155 i != range.last &&
150   - times[i].spaces.include?(overlap_space) then
  156 + @commits[reversed_index(i)].spaces.include?(overlap_space) then
151 157  
152 158 return true;
153 159 end
... ... @@ -282,5 +288,9 @@ module Network
282 288 end
283 289 refs_cache
284 290 end
  291 +
  292 + def reversed_index(index)
  293 + -index - 1
  294 + end
285 295 end
286 296 end
... ...