Commit 46fa92187d6c076619e9cd58877e03c6d15a1f03

Authored by Sato Hiroyuki
1 parent 7587a3b2

Refactor: removing duplicate code.

Showing 1 changed file with 14 additions and 10 deletions   Show diff stats
app/models/network/graph.rb
... ... @@ -25,15 +25,7 @@ module Network
25 25 def collect_commits
26 26 refs_cache = build_refs_cache
27 27  
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   - )
  28 + find_commits(count_to_display_commit_in_center)
37 29 .map do |commit|
38 30 # Decorate with app/model/network/commit.rb
39 31 Network::Commit.new(commit, refs_cache[commit.id])
... ... @@ -74,7 +66,7 @@ module Network
74 66  
75 67 # Skip count that the target commit is displayed in center.
76 68 def count_to_display_commit_in_center
77   - commit_index = Grit::Commit.find_all(@repo, nil, {date_order: true}).index do |c|
  69 + commit_index = find_commits.index do |c|
78 70 c.id == @commit.id
79 71 end
80 72  
... ... @@ -86,6 +78,18 @@ module Network
86 78 end
87 79 end
88 80  
  81 + def find_commits(skip = 0)
  82 + Grit::Commit.find_all(
  83 + @repo,
  84 + nil,
  85 + {
  86 + date_order: true,
  87 + max_count: self.class.max_count,
  88 + skip: skip
  89 + }
  90 + )
  91 + end
  92 +
89 93 def commits_sort_by_ref
90 94 @commits.sort do |a,b|
91 95 if include_ref?(a)
... ...