From 7812cb77c81cb199c7c8fd276130238ccabb856d Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:20:04 +0900 Subject: [PATCH 1/7] Fix typo. --- lib/gitlab/graph/json_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 4b3687e06c3..fc58d7f2dcf 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -49,7 +49,7 @@ module Gitlab # list of commits. As well as returns date list # corelated with time set on commits. # - # @param [Array] comits to index + # @param [Array] commits to index # # @return [Array] list of commit dates corelated with time on commits def index_commits From 1e907498a944c22db79e9cfbd26ee7f10fe1a091 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:34:35 +0900 Subject: [PATCH 2/7] The commit is marked and displayed in the center. --- app/views/graph/show.html.haml | 3 ++- vendor/assets/javascripts/branch-graph.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml index ca3a8706313..4ca75d68f8c 100644 --- a/app/views/graph/show.html.haml +++ b/app/views/graph/show.html.haml @@ -14,6 +14,7 @@ branch_graph = new BranchGraph($("#holder"), { url: '#{project_graph_path(@project, @ref, format: :json)}', commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', - ref: '#{@ref}' + ref: '#{@ref}', + commit_id: '#{@commit && @commit.id}' }); }); diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index 7929d3b2a14..fb22953acd2 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -161,14 +161,23 @@ if (this.commits[i].refs) { this.appendLabel(x, y, this.commits[i].refs); - - // The main branch is displayed in the center. - re = new RegExp('(^| )' + this.options.ref + '( |$)'); - if (this.commits[i].refs.match(re)) { - scrollLeft = x - graphWidth / 2; - } } + // mark commit and displayed in the center + if (this.commits[i].id == this.options.commit_id) { + r.path([ + 'M', x, y - 5, + 'L', x + 4, y - 15, + 'L', x - 4, y - 15, + 'Z' + ]).attr({ + "fill": "#000", + "fill-opacity": .7, + "stroke": "none" + }); + scrollLeft = x - graphWidth / 2; + } + this.appendAnchor(top, this.commits[i], x, y); } top.toFront(); From 81cc1cb87b2056b11640c9887bd40674c9d7925e Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:42:30 +0900 Subject: [PATCH 3/7] Enable to display the commit older than 650th commit. --- app/controllers/graph_controller.rb | 2 +- lib/gitlab/graph/json_builder.rb | 66 ++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb index 30ec5e89db2..c4d745e9ccd 100644 --- a/app/controllers/graph_controller.rb +++ b/app/controllers/graph_controller.rb @@ -10,7 +10,7 @@ class GraphController < ProjectResourceController respond_to do |format| format.html format.json do - graph = Gitlab::Graph::JsonBuilder.new(project, @ref) + graph = Gitlab::Graph::JsonBuilder.new(project, @ref, @commit) render :json => graph.to_json end end diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index fc58d7f2dcf..05e16f3d683 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, {max_count: self.class.max_count, skip: to_commit}).dup # Decorate with app/models/commit.rb @commits.map! { |commit| ::Commit.new(commit) } @@ -53,37 +55,24 @@ module Gitlab # # @return [Array] 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) + 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) + end + + heads.map! do |head| + head.name + end + + heads.include?(@ref) + end + def find_free_parent_spaces(commit, map, times) spaces = [] From 8ff5cf9cd5193b7135f53de3b62dd50bcbbfc2dc Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:46:31 +0900 Subject: [PATCH 4/7] Add search box for the commit. --- app/controllers/graph_controller.rb | 10 ++++++++++ app/views/graph/_head.html.haml | 9 +++++++++ app/views/graph/show.html.haml | 9 +++------ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 app/views/graph/_head.html.haml diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb index c4d745e9ccd..c370433e500 100644 --- a/app/controllers/graph_controller.rb +++ b/app/controllers/graph_controller.rb @@ -7,6 +7,16 @@ class GraphController < ProjectResourceController before_filter :require_non_empty_project def show + if params.has_key?(:q) && params[:q].blank? + redirect_to project_graph_path(@project, params[:id]) + return + end + + if params.has_key?(:q) + @q = params[:q] + @commit = @project.repository.commit(@q) || @commit + end + respond_to do |format| format.html format.json do diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml new file mode 100644 index 00000000000..7e1b46446af --- /dev/null +++ b/app/views/graph/_head.html.haml @@ -0,0 +1,9 @@ +%ul.nav.nav-tabs + %li + = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} + %li.pull-right.search + = form_tag project_graph_path(@project, params[:id]), method: :get, class: 'navbar-form' do |f| + = label_tag :search , "Looking for commit:" + = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input" + +%h3.page_title Project Network Graph diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml index 4ca75d68f8c..e45aca1ddcb 100644 --- a/app/views/graph/show.html.haml +++ b/app/views/graph/show.html.haml @@ -1,7 +1,4 @@ -%h3.page_title Project Network Graph -%br -= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} -%br += render "head" .graph_holder %h4 %small You can move around the graph by using the arrow keys. @@ -12,9 +9,9 @@ var branch_graph; $(function(){ branch_graph = new BranchGraph($("#holder"), { - url: '#{project_graph_path(@project, @ref, format: :json)}', + url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}', commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', ref: '#{@ref}', - commit_id: '#{@commit && @commit.id}' + commit_id: '#{@commit.id}' }); }); From df85c9c06ae3d687bb6ec2f2d11a8ae71fa8ed5f Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 14:59:13 +0900 Subject: [PATCH 5/7] Fix bug when it has been switched to tag. --- lib/extracts_path.rb | 5 ++++- lib/gitlab/graph/json_builder.rb | 2 +- 2 files changed, 5 insertions(+), 2 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 05e16f3d683..8f31c820be1 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -113,7 +113,7 @@ module Gitlab def include_ref?(commit) heads = commit.refs.select do |ref| - ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) + ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) or ref.is_a?(Grit::Tag) end heads.map! do |head| From 9dccecc9b54240a7088ceac554c3f9b6b24d51f7 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 19:58:49 +0900 Subject: [PATCH 6/7] Sort the commits on network graph by commiter date. Author date is not updated, if the commits is rebased. So the network graph having many rebased commit turns round and round, that it is very difficult to undarstand history. --- lib/gitlab/graph/json_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 8f31c820be1..cc971a245a7 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -33,7 +33,7 @@ module Gitlab # def collect_commits - @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count, skip: to_commit}).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) } @@ -86,7 +86,7 @@ module Gitlab # Skip count that the target commit is displayed in center. def to_commit - commits = Grit::Commit.find_all(repo, nil) + commits = Grit::Commit.find_all(repo, nil, {topo_order: true}) commit_index = commits.index do |c| c.id == @commit.id end From 622dae76cc0e9e3c76c5d2ba18efeb139644881e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 12 Feb 2013 19:22:40 +0200 Subject: [PATCH 7/7] style network graph form a bit --- .../stylesheets/gitlab_bootstrap/common.scss | 1 + app/views/graph/_head.html.haml | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/gitlab_bootstrap/common.scss b/app/assets/stylesheets/gitlab_bootstrap/common.scss index cb292bc711f..dcfd610e2c4 100644 --- a/app/assets/stylesheets/gitlab_bootstrap/common.scss +++ b/app/assets/stylesheets/gitlab_bootstrap/common.scss @@ -20,6 +20,7 @@ .hint { font-style: italic; color: #999; } .light { color: #888 } .tiny { font-weight: normal } +.vtop { vertical-align: top; } /** ALERT MESSAGES **/ diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml index 7e1b46446af..fba9a958a19 100644 --- a/app/views/graph/_head.html.haml +++ b/app/views/graph/_head.html.haml @@ -1,9 +1,16 @@ -%ul.nav.nav-tabs - %li - = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} - %li.pull-right.search - = form_tag project_graph_path(@project, params[:id]), method: :get, class: 'navbar-form' do |f| - = label_tag :search , "Looking for commit:" - = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input" - %h3.page_title Project Network Graph +%hr + +.clearfix + .pull-left + = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} + + .search.pull-right + = form_tag project_graph_path(@project, params[:id]), method: :get do |f| + .control-group + = label_tag :search , "Looking for commit:", class: 'control-label light' + .controls + = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input xlarge" + = button_tag type: 'submit', class: 'btn vtop' do + %i.icon-search +