Commit ccc712b1983f49216fc85deb61a7e5efd7790936
1 parent
8c5003cf
Exists in
master
and in
4 other branches
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,13 +23,21 @@ module Network | ||
23 | # Get commits from repository | 23 | # Get commits from repository |
24 | # | 24 | # |
25 | def collect_commits | 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 | refs_cache = build_refs_cache | 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 | end | 41 | end |
34 | 42 | ||
35 | # Method is adding time and space on the | 43 | # Method is adding time and space on the |
@@ -40,14 +48,13 @@ module Network | @@ -40,14 +48,13 @@ module Network | ||
40 | # | 48 | # |
41 | # @return [Array<TimeDate>] list of commit dates corelated with time on commits | 49 | # @return [Array<TimeDate>] list of commit dates corelated with time on commits |
42 | def index_commits | 50 | def index_commits |
43 | - days, times = [], [] | 51 | + days = [] |
44 | map = {} | 52 | map = {} |
45 | 53 | ||
46 | - commits.reverse.each_with_index do |c,i| | 54 | + @commits.reverse.each_with_index do |c,i| |
47 | c.time = i | 55 | c.time = i |
48 | days[i] = c.committed_date | 56 | days[i] = c.committed_date |
49 | map[c.id] = c | 57 | map[c.id] = c |
50 | - times[i] = c | ||
51 | end | 58 | end |
52 | 59 | ||
53 | @_reserved = {} | 60 | @_reserved = {} |
@@ -62,17 +69,16 @@ module Network | @@ -62,17 +69,16 @@ module Network | ||
62 | end | 69 | end |
63 | 70 | ||
64 | # find parent spaces for not overlap lines | 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 | end | 74 | end |
68 | 75 | ||
69 | days | 76 | days |
70 | end | 77 | end |
71 | 78 | ||
72 | # Skip count that the target commit is displayed in center. | 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 | c.id == @commit.id | 82 | c.id == @commit.id |
77 | end | 83 | end |
78 | 84 | ||
@@ -85,7 +91,7 @@ module Network | @@ -85,7 +91,7 @@ module Network | ||
85 | end | 91 | end |
86 | 92 | ||
87 | def commits_sort_by_ref | 93 | def commits_sort_by_ref |
88 | - commits.sort do |a,b| | 94 | + @commits.sort do |a,b| |
89 | if include_ref?(a) | 95 | if include_ref?(a) |
90 | -1 | 96 | -1 |
91 | elsif include_ref?(b) | 97 | elsif include_ref?(b) |
@@ -108,7 +114,7 @@ module Network | @@ -108,7 +114,7 @@ module Network | ||
108 | heads.include?(@ref) | 114 | heads.include?(@ref) |
109 | end | 115 | end |
110 | 116 | ||
111 | - def find_free_parent_spaces(commit, map, times) | 117 | + def find_free_parent_spaces(commit, map) |
112 | spaces = [] | 118 | spaces = [] |
113 | 119 | ||
114 | commit.parents.each do |p| | 120 | commit.parents.each do |p| |
@@ -122,9 +128,9 @@ module Network | @@ -122,9 +128,9 @@ module Network | ||
122 | end | 128 | end |
123 | 129 | ||
124 | space = if commit.space >= parent.space then | 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 | else | 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 | end | 134 | end |
129 | 135 | ||
130 | mark_reserved(range, space) | 136 | mark_reserved(range, space) |
@@ -135,19 +141,19 @@ module Network | @@ -135,19 +141,19 @@ module Network | ||
135 | spaces | 141 | spaces |
136 | end | 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 | find_free_space(range, space_step, space_base, space_default) | 146 | find_free_space(range, space_step, space_base, space_default) |
141 | else | 147 | else |
142 | space_default | 148 | space_default |
143 | end | 149 | end |
144 | end | 150 | end |
145 | 151 | ||
146 | - def is_overlap?(range, times, overlap_space) | 152 | + def is_overlap?(range, overlap_space) |
147 | range.each do |i| | 153 | range.each do |i| |
148 | if i != range.first && | 154 | if i != range.first && |
149 | i != range.last && | 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 | return true; | 158 | return true; |
153 | end | 159 | end |
@@ -282,5 +288,9 @@ module Network | @@ -282,5 +288,9 @@ module Network | ||
282 | end | 288 | end |
283 | refs_cache | 289 | refs_cache |
284 | end | 290 | end |
291 | + | ||
292 | + def reversed_index(index) | ||
293 | + -index - 1 | ||
294 | + end | ||
285 | end | 295 | end |
286 | end | 296 | end |