Commit fd0afcc996d687232c1181263b17793b2827d44e

Authored by Hiroyuki Sato
1 parent 65cba5c6

Remove the dependancy of grit from class Network::Graph

app/helpers/graph_helper.rb
1 1 module GraphHelper
2   - def get_refs(commit)
  2 + def get_refs(repo, commit)
3 3 refs = ""
4   - refs += commit.refs.collect{|r|r.name}.join(" ") if commit.refs
  4 + refs += commit.ref_names(repo).join(" ")
5 5  
6 6 # append note count
7 7 refs += "[#{@graph.notes[commit.id]}]" if @graph.notes[commit.id] > 0
... ...
app/models/network/commit.rb
... ... @@ -4,15 +4,13 @@ module Network
4 4 class Commit
5 5 include ActionView::Helpers::TagHelper
6 6  
7   - attr_reader :refs
8 7 attr_accessor :time, :spaces, :parent_spaces
9 8  
10   - def initialize(raw_commit, refs)
11   - @commit = Gitlab::Git::Commit.new(raw_commit)
  9 + def initialize(raw_commit)
  10 + @commit = raw_commit
12 11 @time = -1
13 12 @spaces = []
14 13 @parent_spaces = []
15   - @refs = refs || []
16 14 end
17 15  
18 16 def method_missing(m, *args, &block)
... ...
app/models/network/graph.rb
1   -require "grit"
2   -
3 1 module Network
4 2 class Graph
5   - attr_reader :days, :commits, :map, :notes
  3 + attr_reader :days, :commits, :map, :notes, :repo
6 4  
7 5 def self.max_count
8 6 @max_count ||= 650
... ... @@ -13,7 +11,7 @@ module Network
13 11 @ref = ref
14 12 @commit = commit
15 13 @filter_ref = filter_ref
16   - @repo = project.repo
  14 + @repo = project.repository
17 15  
18 16 @commits = collect_commits
19 17 @days = index_commits
... ... @@ -33,11 +31,9 @@ module Network
33 31 # Get commits from repository
34 32 #
35 33 def collect_commits
36   - refs_cache = build_refs_cache
37   -
38 34 find_commits(count_to_display_commit_in_center).map do |commit|
39 35 # Decorate with app/model/network/commit.rb
40   - Network::Commit.new(commit, refs_cache[commit.id])
  36 + Network::Commit.new(commit)
41 37 end
42 38 end
43 39  
... ... @@ -103,14 +99,13 @@ module Network
103 99  
104 100 def find_commits(skip = 0)
105 101 opts = {
106   - date_order: true,
107 102 max_count: self.class.max_count,
108 103 skip: skip
109 104 }
110 105  
111   - ref = @ref if @filter_ref
  106 + opts[:ref] = @commit.id if @filter_ref
112 107  
113   - Grit::Commit.find_all(@repo, ref, opts)
  108 + @repo.find_commits(opts)
114 109 end
115 110  
116 111 def commits_sort_by_ref
... ... @@ -126,15 +121,7 @@ module Network
126 121 end
127 122  
128 123 def include_ref?(commit)
129   - heads = commit.refs.select do |ref|
130   - ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) or ref.is_a?(Grit::Tag)
131   - end
132   -
133   - heads.map! do |head|
134   - head.name
135   - end
136   -
137   - heads.include?(@ref)
  124 + commit.ref_names(@repo).include?(@ref)
138 125 end
139 126  
140 127 def find_free_parent_spaces(commit)
... ... @@ -282,14 +269,5 @@ module Network
282 269 leaves.push(commit)
283 270 end
284 271 end
285   -
286   - def build_refs_cache
287   - refs_cache = {}
288   - @repo.refs.each do |ref|
289   - refs_cache[ref.commit.id] = [] unless refs_cache.include?(ref.commit.id)
290   - refs_cache[ref.commit.id] << ref
291   - end
292   - refs_cache
293   - end
294 272 end
295 273 end
... ...
app/views/projects/network/show.json.erb
... ... @@ -13,7 +13,7 @@
13 13 },
14 14 time: c.time,
15 15 space: c.spaces.first,
16   - refs: get_refs(c),
  16 + refs: get_refs(@graph.repo, c),
17 17 id: c.sha,
18 18 date: c.date,
19 19 message: c.message,
... ...