Commit ddea7d1689e1bbe62d6f226986e51ce7a0eb835d
Exists in
master
and in
4 other branches
Merge branch 'easy-to-find-commit-on-network-graph' of https://github.com/hiropo…
…nz/gitlabhq into hiroponz-easy-to-find-commit-on-network-graph
Showing
6 changed files
with
91 additions
and
34 deletions
Show diff stats
app/controllers/graph_controller.rb
@@ -7,10 +7,20 @@ class GraphController < ProjectResourceController | @@ -7,10 +7,20 @@ class GraphController < ProjectResourceController | ||
7 | before_filter :require_non_empty_project | 7 | before_filter :require_non_empty_project |
8 | 8 | ||
9 | def show | 9 | def show |
10 | + if params.has_key?(:q) && params[:q].blank? | ||
11 | + redirect_to project_graph_path(@project, params[:id]) | ||
12 | + return | ||
13 | + end | ||
14 | + | ||
15 | + if params.has_key?(:q) | ||
16 | + @q = params[:q] | ||
17 | + @commit = @project.repository.commit(@q) || @commit | ||
18 | + end | ||
19 | + | ||
10 | respond_to do |format| | 20 | respond_to do |format| |
11 | format.html | 21 | format.html |
12 | format.json do | 22 | format.json do |
13 | - graph = Gitlab::Graph::JsonBuilder.new(project, @ref) | 23 | + graph = Gitlab::Graph::JsonBuilder.new(project, @ref, @commit) |
14 | render :json => graph.to_json | 24 | render :json => graph.to_json |
15 | end | 25 | end |
16 | end | 26 | end |
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +%ul.nav.nav-tabs | ||
2 | + %li | ||
3 | + = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} | ||
4 | + %li.pull-right.search | ||
5 | + = form_tag project_graph_path(@project, params[:id]), method: :get, class: 'navbar-form' do |f| | ||
6 | + = label_tag :search , "Looking for commit:" | ||
7 | + = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input" | ||
8 | + | ||
9 | +%h3.page_title Project Network Graph |
app/views/graph/show.html.haml
1 | -%h3.page_title Project Network Graph | ||
2 | -%br | ||
3 | -= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} | ||
4 | -%br | 1 | += render "head" |
5 | .graph_holder | 2 | .graph_holder |
6 | %h4 | 3 | %h4 |
7 | %small You can move around the graph by using the arrow keys. | 4 | %small You can move around the graph by using the arrow keys. |
@@ -12,8 +9,9 @@ | @@ -12,8 +9,9 @@ | ||
12 | var branch_graph; | 9 | var branch_graph; |
13 | $(function(){ | 10 | $(function(){ |
14 | branch_graph = new BranchGraph($("#holder"), { | 11 | branch_graph = new BranchGraph($("#holder"), { |
15 | - url: '#{project_graph_path(@project, @ref, format: :json)}', | 12 | + url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}', |
16 | commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', | 13 | commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', |
17 | - ref: '#{@ref}' | 14 | + ref: '#{@ref}', |
15 | + commit_id: '#{@commit.id}' | ||
18 | }); | 16 | }); |
19 | }); | 17 | }); |
lib/extracts_path.rb
@@ -117,7 +117,10 @@ module ExtractsPath | @@ -117,7 +117,10 @@ module ExtractsPath | ||
117 | 117 | ||
118 | @id = File.join(@ref, @path) | 118 | @id = File.join(@ref, @path) |
119 | 119 | ||
120 | - @commit = CommitDecorator.decorate(@project.repository.commit(@ref)) | 120 | + # It is used "@project.repository.commits(@ref, @path, 1, 0)", |
121 | + # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. | ||
122 | + commits = @project.repository.commits(@ref, @path, 1, 0) | ||
123 | + @commit = CommitDecorator.decorate(commits.first) | ||
121 | 124 | ||
122 | @tree = Tree.new(@commit.tree, @ref, @path) | 125 | @tree = Tree.new(@commit.tree, @ref, @path) |
123 | @tree = TreeDecorator.new(@tree) | 126 | @tree = TreeDecorator.new(@tree) |
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, {topo_order: true, 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) } |
@@ -49,41 +51,28 @@ module Gitlab | @@ -49,41 +51,28 @@ module Gitlab | ||
49 | # list of commits. As well as returns date list | 51 | # list of commits. As well as returns date list |
50 | # corelated with time set on commits. | 52 | # corelated with time set on commits. |
51 | # | 53 | # |
52 | - # @param [Array<Graph::Commit>] comits to index | 54 | + # @param [Array<Graph::Commit>] commits to index |
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, {topo_order: true}) | ||
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) or ref.is_a?(Grit::Tag) | ||
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 |
vendor/assets/javascripts/branch-graph.js
@@ -161,14 +161,23 @@ | @@ -161,14 +161,23 @@ | ||
161 | 161 | ||
162 | if (this.commits[i].refs) { | 162 | if (this.commits[i].refs) { |
163 | this.appendLabel(x, y, this.commits[i].refs); | 163 | this.appendLabel(x, y, this.commits[i].refs); |
164 | - | ||
165 | - // The main branch is displayed in the center. | ||
166 | - re = new RegExp('(^| )' + this.options.ref + '( |$)'); | ||
167 | - if (this.commits[i].refs.match(re)) { | ||
168 | - scrollLeft = x - graphWidth / 2; | ||
169 | - } | ||
170 | } | 164 | } |
171 | 165 | ||
166 | + // mark commit and displayed in the center | ||
167 | + if (this.commits[i].id == this.options.commit_id) { | ||
168 | + r.path([ | ||
169 | + 'M', x, y - 5, | ||
170 | + 'L', x + 4, y - 15, | ||
171 | + 'L', x - 4, y - 15, | ||
172 | + 'Z' | ||
173 | + ]).attr({ | ||
174 | + "fill": "#000", | ||
175 | + "fill-opacity": .7, | ||
176 | + "stroke": "none" | ||
177 | + }); | ||
178 | + scrollLeft = x - graphWidth / 2; | ||
179 | + } | ||
180 | + | ||
172 | this.appendAnchor(top, this.commits[i], x, y); | 181 | this.appendAnchor(top, this.commits[i], x, y); |
173 | } | 182 | } |
174 | top.toFront(); | 183 | top.toFront(); |