Commit 81cc1cb87b2056b11640c9887bd40674c9d7925e
1 parent
1e907498
Exists in
master
and in
4 other branches
Enable to display the commit older than 650th commit.
Showing
2 changed files
with
48 additions
and
20 deletions
Show diff stats
app/controllers/graph_controller.rb
| @@ -10,7 +10,7 @@ class GraphController < ProjectResourceController | @@ -10,7 +10,7 @@ class GraphController < ProjectResourceController | ||
| 10 | respond_to do |format| | 10 | respond_to do |format| |
| 11 | format.html | 11 | format.html |
| 12 | format.json do | 12 | format.json do |
| 13 | - graph = Gitlab::Graph::JsonBuilder.new(project, @ref) | 13 | + graph = Gitlab::Graph::JsonBuilder.new(project, @ref, @commit) |
| 14 | render :json => graph.to_json | 14 | render :json => graph.to_json |
| 15 | end | 15 | end |
| 16 | end | 16 | end |
lib/gitlab/graph/json_builder.rb
| @@ -9,9 +9,10 @@ module Gitlab | @@ -9,9 +9,10 @@ module Gitlab | ||
| 9 | @max_count ||= 650 | 9 | @max_count ||= 650 |
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | - def initialize project, ref | 12 | + def initialize project, ref, commit |
| 13 | @project = project | 13 | @project = project |
| 14 | @ref = ref | 14 | @ref = ref |
| 15 | + @commit = commit | ||
| 15 | @repo = project.repo | 16 | @repo = project.repo |
| 16 | @ref_cache = {} | 17 | @ref_cache = {} |
| 17 | 18 | ||
| @@ -31,7 +32,8 @@ module Gitlab | @@ -31,7 +32,8 @@ module Gitlab | ||
| 31 | # Get commits from repository | 32 | # Get commits from repository |
| 32 | # | 33 | # |
| 33 | def collect_commits | 34 | def collect_commits |
| 34 | - @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count}).dup | 35 | + |
| 36 | + @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count, skip: to_commit}).dup | ||
| 35 | 37 | ||
| 36 | # Decorate with app/models/commit.rb | 38 | # Decorate with app/models/commit.rb |
| 37 | @commits.map! { |commit| ::Commit.new(commit) } | 39 | @commits.map! { |commit| ::Commit.new(commit) } |
| @@ -53,37 +55,24 @@ module Gitlab | @@ -53,37 +55,24 @@ module Gitlab | ||
| 53 | # | 55 | # |
| 54 | # @return [Array<TimeDate>] list of commit dates corelated with time on commits | 56 | # @return [Array<TimeDate>] list of commit dates corelated with time on commits |
| 55 | def index_commits | 57 | def index_commits |
| 56 | - days, heads, times = [], [], [] | 58 | + days, times = [], [] |
| 57 | map = {} | 59 | map = {} |
| 58 | 60 | ||
| 59 | commits.reverse.each_with_index do |c,i| | 61 | commits.reverse.each_with_index do |c,i| |
| 60 | c.time = i | 62 | c.time = i |
| 61 | days[i] = c.committed_date | 63 | days[i] = c.committed_date |
| 62 | map[c.id] = c | 64 | map[c.id] = c |
| 63 | - heads += c.refs unless c.refs.nil? | ||
| 64 | times[i] = c | 65 | times[i] = c |
| 65 | end | 66 | end |
| 66 | 67 | ||
| 67 | - heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} | ||
| 68 | - # sort heads so the master is top and current branches are closer | ||
| 69 | - heads.sort! do |a,b| | ||
| 70 | - if a.name == @ref | ||
| 71 | - -1 | ||
| 72 | - elsif b.name == @ref | ||
| 73 | - 1 | ||
| 74 | - else | ||
| 75 | - b.commit.committed_date <=> a.commit.committed_date | ||
| 76 | - end | ||
| 77 | - end | ||
| 78 | - | ||
| 79 | @_reserved = {} | 68 | @_reserved = {} |
| 80 | days.each_index do |i| | 69 | days.each_index do |i| |
| 81 | @_reserved[i] = [] | 70 | @_reserved[i] = [] |
| 82 | end | 71 | end |
| 83 | 72 | ||
| 84 | - heads.each do |h| | ||
| 85 | - if map.include? h.commit.id then | ||
| 86 | - place_chain(map[h.commit.id], map) | 73 | + commits_sort_by_ref.each do |commit| |
| 74 | + if map.include? commit.id then | ||
| 75 | + place_chain(map[commit.id], map) | ||
| 87 | end | 76 | end |
| 88 | end | 77 | end |
| 89 | 78 | ||
| @@ -95,6 +84,45 @@ module Gitlab | @@ -95,6 +84,45 @@ module Gitlab | ||
| 95 | days | 84 | days |
| 96 | end | 85 | end |
| 97 | 86 | ||
| 87 | + # Skip count that the target commit is displayed in center. | ||
| 88 | + def to_commit | ||
| 89 | + commits = Grit::Commit.find_all(repo, nil) | ||
| 90 | + commit_index = commits.index do |c| | ||
| 91 | + c.id == @commit.id | ||
| 92 | + end | ||
| 93 | + | ||
| 94 | + if commit_index && (self.class.max_count / 2 < commit_index) then | ||
| 95 | + # get max index that commit is displayed in the center. | ||
| 96 | + commit_index - self.class.max_count / 2 | ||
| 97 | + else | ||
| 98 | + 0 | ||
| 99 | + end | ||
| 100 | + end | ||
| 101 | + | ||
| 102 | + def commits_sort_by_ref | ||
| 103 | + commits.sort do |a,b| | ||
| 104 | + if include_ref?(a) | ||
| 105 | + -1 | ||
| 106 | + elsif include_ref?(b) | ||
| 107 | + 1 | ||
| 108 | + else | ||
| 109 | + b.committed_date <=> a.committed_date | ||
| 110 | + end | ||
| 111 | + end | ||
| 112 | + end | ||
| 113 | + | ||
| 114 | + def include_ref?(commit) | ||
| 115 | + heads = commit.refs.select do |ref| | ||
| 116 | + ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) | ||
| 117 | + end | ||
| 118 | + | ||
| 119 | + heads.map! do |head| | ||
| 120 | + head.name | ||
| 121 | + end | ||
| 122 | + | ||
| 123 | + heads.include?(@ref) | ||
| 124 | + end | ||
| 125 | + | ||
| 98 | def find_free_parent_spaces(commit, map, times) | 126 | def find_free_parent_spaces(commit, map, times) |
| 99 | spaces = [] | 127 | spaces = [] |
| 100 | 128 |