Commit d04ad4cb5dc9974bec39b70bac4a2590e4436e14
Exists in
master
and in
4 other branches
Merge pull request #4812 from hiroponz/remove-dependancy-of-grit
Remove the dependancy of grit from class Network::Graph
Showing
4 changed files
with
11 additions
and
35 deletions
Show diff stats
app/helpers/graph_helper.rb
| 1 | module GraphHelper | 1 | module GraphHelper |
| 2 | - def get_refs(commit) | 2 | + def get_refs(repo, commit) |
| 3 | refs = "" | 3 | refs = "" |
| 4 | - refs += commit.refs.collect{|r|r.name}.join(" ") if commit.refs | 4 | + refs += commit.ref_names(repo).join(" ") |
| 5 | 5 | ||
| 6 | # append note count | 6 | # append note count |
| 7 | refs += "[#{@graph.notes[commit.id]}]" if @graph.notes[commit.id] > 0 | 7 | refs += "[#{@graph.notes[commit.id]}]" if @graph.notes[commit.id] > 0 |
app/models/network/commit.rb
| @@ -4,15 +4,13 @@ module Network | @@ -4,15 +4,13 @@ module Network | ||
| 4 | class Commit | 4 | class Commit |
| 5 | include ActionView::Helpers::TagHelper | 5 | include ActionView::Helpers::TagHelper |
| 6 | 6 | ||
| 7 | - attr_reader :refs | ||
| 8 | attr_accessor :time, :spaces, :parent_spaces | 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 | @time = -1 | 11 | @time = -1 |
| 13 | @spaces = [] | 12 | @spaces = [] |
| 14 | @parent_spaces = [] | 13 | @parent_spaces = [] |
| 15 | - @refs = refs || [] | ||
| 16 | end | 14 | end |
| 17 | 15 | ||
| 18 | def method_missing(m, *args, &block) | 16 | def method_missing(m, *args, &block) |
app/models/network/graph.rb
| 1 | -require "grit" | ||
| 2 | - | ||
| 3 | module Network | 1 | module Network |
| 4 | class Graph | 2 | class Graph |
| 5 | - attr_reader :days, :commits, :map, :notes | 3 | + attr_reader :days, :commits, :map, :notes, :repo |
| 6 | 4 | ||
| 7 | def self.max_count | 5 | def self.max_count |
| 8 | @max_count ||= 650 | 6 | @max_count ||= 650 |
| @@ -13,7 +11,7 @@ module Network | @@ -13,7 +11,7 @@ module Network | ||
| 13 | @ref = ref | 11 | @ref = ref |
| 14 | @commit = commit | 12 | @commit = commit |
| 15 | @filter_ref = filter_ref | 13 | @filter_ref = filter_ref |
| 16 | - @repo = project.repo | 14 | + @repo = project.repository |
| 17 | 15 | ||
| 18 | @commits = collect_commits | 16 | @commits = collect_commits |
| 19 | @days = index_commits | 17 | @days = index_commits |
| @@ -33,11 +31,9 @@ module Network | @@ -33,11 +31,9 @@ module Network | ||
| 33 | # Get commits from repository | 31 | # Get commits from repository |
| 34 | # | 32 | # |
| 35 | def collect_commits | 33 | def collect_commits |
| 36 | - refs_cache = build_refs_cache | ||
| 37 | - | ||
| 38 | find_commits(count_to_display_commit_in_center).map do |commit| | 34 | find_commits(count_to_display_commit_in_center).map do |commit| |
| 39 | # Decorate with app/model/network/commit.rb | 35 | # Decorate with app/model/network/commit.rb |
| 40 | - Network::Commit.new(commit, refs_cache[commit.id]) | 36 | + Network::Commit.new(commit) |
| 41 | end | 37 | end |
| 42 | end | 38 | end |
| 43 | 39 | ||
| @@ -103,14 +99,13 @@ module Network | @@ -103,14 +99,13 @@ module Network | ||
| 103 | 99 | ||
| 104 | def find_commits(skip = 0) | 100 | def find_commits(skip = 0) |
| 105 | opts = { | 101 | opts = { |
| 106 | - date_order: true, | ||
| 107 | max_count: self.class.max_count, | 102 | max_count: self.class.max_count, |
| 108 | skip: skip | 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 | end | 109 | end |
| 115 | 110 | ||
| 116 | def commits_sort_by_ref | 111 | def commits_sort_by_ref |
| @@ -126,15 +121,7 @@ module Network | @@ -126,15 +121,7 @@ module Network | ||
| 126 | end | 121 | end |
| 127 | 122 | ||
| 128 | def include_ref?(commit) | 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 | end | 125 | end |
| 139 | 126 | ||
| 140 | def find_free_parent_spaces(commit) | 127 | def find_free_parent_spaces(commit) |
| @@ -282,14 +269,5 @@ module Network | @@ -282,14 +269,5 @@ module Network | ||
| 282 | leaves.push(commit) | 269 | leaves.push(commit) |
| 283 | end | 270 | end |
| 284 | end | 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 | end | 272 | end |
| 295 | end | 273 | end |
app/views/projects/network/show.json.erb
| @@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
| 13 | }, | 13 | }, |
| 14 | time: c.time, | 14 | time: c.time, |
| 15 | space: c.spaces.first, | 15 | space: c.spaces.first, |
| 16 | - refs: get_refs(c), | 16 | + refs: get_refs(@graph.repo, c), |
| 17 | id: c.sha, | 17 | id: c.sha, |
| 18 | date: c.date, | 18 | date: c.date, |
| 19 | message: c.message, | 19 | message: c.message, |