diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-12 21:02:05 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-12 21:02:05 +0400 |
commit | ddea7d1689e1bbe62d6f226986e51ce7a0eb835d (patch) | |
tree | e07f673c116bcba16acb7fec9f79bda73cdedf14 /lib | |
parent | d6513b5153ae2d8bdfc3017f0cbbe909678dd37c (diff) | |
parent | 9dccecc9b54240a7088ceac554c3f9b6b24d51f7 (diff) |
Merge branch 'easy-to-find-commit-on-network-graph' of https://github.com/hiroponz/gitlabhq into hiroponz-easy-to-find-commit-on-network-graph
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extracts_path.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/graph/json_builder.rb | 68 |
2 files changed, 52 insertions, 21 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 976ac018204..fb595e18b24 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -117,7 +117,10 @@ module ExtractsPath @id = File.join(@ref, @path) - @commit = CommitDecorator.decorate(@project.repository.commit(@ref)) + # It is used "@project.repository.commits(@ref, @path, 1, 0)", + # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. + commits = @project.repository.commits(@ref, @path, 1, 0) + @commit = CommitDecorator.decorate(commits.first) @tree = Tree.new(@commit.tree, @ref, @path) @tree = TreeDecorator.new(@tree) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 4b3687e06c3..cc971a245a7 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -9,9 +9,10 @@ module Gitlab @max_count ||= 650 end - def initialize project, ref + def initialize project, ref, commit @project = project @ref = ref + @commit = commit @repo = project.repo @ref_cache = {} @@ -31,7 +32,8 @@ module Gitlab # Get commits from repository # def collect_commits - @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count}).dup + + @commits = Grit::Commit.find_all(repo, nil, {topo_order: true, max_count: self.class.max_count, skip: to_commit}).dup # Decorate with app/models/commit.rb @commits.map! { |commit| ::Commit.new(commit) } @@ -49,41 +51,28 @@ module Gitlab # list of commits. As well as returns date list # corelated with time set on commits. # - # @param [Array<Graph::Commit>] comits to index + # @param [Array<Graph::Commit>] commits to index # # @return [Array<TimeDate>] list of commit dates corelated with time on commits def index_commits - days, heads, times = [], [], [] + days, times = [], [] map = {} commits.reverse.each_with_index do |c,i| c.time = i days[i] = c.committed_date map[c.id] = c - heads += c.refs unless c.refs.nil? times[i] = c end - heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} - # sort heads so the master is top and current branches are closer - heads.sort! do |a,b| - if a.name == @ref - -1 - elsif b.name == @ref - 1 - else - b.commit.committed_date <=> a.commit.committed_date - end - end - @_reserved = {} days.each_index do |i| @_reserved[i] = [] end - heads.each do |h| - if map.include? h.commit.id then - place_chain(map[h.commit.id], map) + commits_sort_by_ref.each do |commit| + if map.include? commit.id then + place_chain(map[commit.id], map) end end @@ -95,6 +84,45 @@ module Gitlab days end + # Skip count that the target commit is displayed in center. + def to_commit + commits = Grit::Commit.find_all(repo, nil, {topo_order: true}) + commit_index = commits.index do |c| + c.id == @commit.id + end + + if commit_index && (self.class.max_count / 2 < commit_index) then + # get max index that commit is displayed in the center. + commit_index - self.class.max_count / 2 + else + 0 + end + end + + def commits_sort_by_ref + commits.sort do |a,b| + if include_ref?(a) + -1 + elsif include_ref?(b) + 1 + else + b.committed_date <=> a.committed_date + end + end + end + + def include_ref?(commit) + heads = commit.refs.select do |ref| + ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) or ref.is_a?(Grit::Tag) + end + + heads.map! do |head| + head.name + end + + heads.include?(@ref) + end + def find_free_parent_spaces(commit, map, times) spaces = [] |