diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-02-06 22:32:04 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-02-06 22:32:04 +0200 |
commit | 422e43989b0e35f3773c7e91f3d04c0baec0fb14 (patch) | |
tree | 3f14f89d40022a2b62830c873dba18c2a7f3e894 | |
parent | 6c416aaac85fe16cd4900a686714627e9a0fcdbc (diff) | |
download | gitlab-ce-422e43989b0e35f3773c7e91f3d04c0baec0fb14.tar.gz |
Compare view for commits
-rw-r--r-- | app/assets/stylesheets/commits.css.scss | 7 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 23 | ||||
-rw-r--r-- | app/views/commits/_commit.html.haml | 13 | ||||
-rw-r--r-- | app/views/commits/_commits.html.haml | 15 | ||||
-rw-r--r-- | app/views/commits/_diffs.html.haml (renamed from app/views/commits/_diff.html.haml) | 5 | ||||
-rw-r--r-- | app/views/commits/_head.html.haml | 22 | ||||
-rw-r--r-- | app/views/commits/compare.html.haml | 49 | ||||
-rw-r--r-- | app/views/commits/index.html.haml | 8 | ||||
-rw-r--r-- | app/views/commits/show.html.haml | 2 | ||||
-rw-r--r-- | app/views/merge_requests/_commits.html.haml | 11 | ||||
-rw-r--r-- | app/views/merge_requests/_diffs.html.haml | 25 | ||||
-rw-r--r-- | config/routes.rb | 6 | ||||
-rw-r--r-- | spec/requests/commits_spec.rb | 10 |
13 files changed, 135 insertions, 61 deletions
diff --git a/app/assets/stylesheets/commits.css.scss b/app/assets/stylesheets/commits.css.scss index 05630f7a338..691b3d86eb5 100644 --- a/app/assets/stylesheets/commits.css.scss +++ b/app/assets/stylesheets/commits.css.scss @@ -134,3 +134,10 @@ ul.bordered-list li:last-child { border:none } margin:2px; } } + +.project-refs-form.commit-refs-form .chzn-container { + position: relative; + top: 0; + left: 0; + margin-right: 10px; +} diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index e2853dd6cf6..73d28a555e5 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -9,6 +9,7 @@ class CommitsController < ApplicationController before_filter :authorize_read_project! before_filter :require_non_empty_project before_filter :load_refs, :only => :index # load @branch, @tag & @ref + before_filter :render_full_content def index @repo = project.repo @@ -29,11 +30,29 @@ class CommitsController < ApplicationController @line_notes = project.commit_line_notes(@commit) - render_full_content - respond_to do |format| format.html format.js { respond_with_notes } end end + + def compare + first = project.commit(params[:to]) + last = project.commit(params[:from]) + + @diffs = [] + @commits = [] + @line_notes = [] + + if first && last + commits = [first, last].sort_by(&:created_at) + younger = commits.first + older = commits.last + + + @commits = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} + @diffs = project.repo.diff(younger.id, older.id) rescue [] + @commit = older + end + end end diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml new file mode 100644 index 00000000000..c2a8c975952 --- /dev/null +++ b/app/views/commits/_commit.html.haml @@ -0,0 +1,13 @@ +%li.entry + = link_to project_commit_path(@project, :id => commit.id) do + %div + %strong + = truncate commit.id.to_s, :length => 10 + – + = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 + = truncate(commit.safe_message, :length => 50) + + %span.right.cgray + = time_ago_in_words(commit.committed_date) + ago + diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml index cdea9acb9d6..1394207e192 100644 --- a/app/views/commits/_commits.html.haml +++ b/app/views/commits/_commits.html.haml @@ -3,17 +3,4 @@ .day-commits-table %h5.underlined= day.stamp("28 Aug, 2010") %br - %ul.unstyled - - commits.each do |commit| - %li.entry - = link_to project_commit_path(@project, :id => commit.id) do - %div - %strong - = truncate commit.id.to_s, :length => 10 - – - = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 - = truncate(commit.safe_message, :length => 50) - - %span.right.cgray - = time_ago_in_words(commit.committed_date) - ago + %ul.unstyled= render commits diff --git a/app/views/commits/_diff.html.haml b/app/views/commits/_diffs.html.haml index cf5ef60512f..8f65afcd02c 100644 --- a/app/views/commits/_diff.html.haml +++ b/app/views/commits/_diffs.html.haml @@ -1,7 +1,7 @@ .file_stats - = render "commits/diff_head", :diffs => @commit.diffs + = render "commits/diff_head", :diffs => diffs -- @commit.diffs.each_with_index do |diff, i| +- diffs.each_with_index do |diff, i| - next if diff.diff.empty? - file = (@commit.tree / diff.b_path) - next unless file @@ -22,3 +22,4 @@ - else %p %center No preview for this file type + diff --git a/app/views/commits/_head.html.haml b/app/views/commits/_head.html.haml new file mode 100644 index 00000000000..f6facea8b56 --- /dev/null +++ b/app/views/commits/_head.html.haml @@ -0,0 +1,22 @@ +%ul.tabs + %li + = form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form commit-refs-form" do + = select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select" + = hidden_field_tag :destination, "commits" + + %li{:class => "#{'active' if current_page?(project_commits_path(@project)) }"} + = link_to project_commits_path(@project) do + %span + Commits + %li{:class => "#{'active' if current_page?(compare_project_commits_path(@project)) }"} + = link_to compare_project_commits_path(@project) do + %span + Compare + + + + +:javascript + $(function(){ + $('.project-refs-select').chosen(); + }); diff --git a/app/views/commits/compare.html.haml b/app/views/commits/compare.html.haml new file mode 100644 index 00000000000..877bd40709b --- /dev/null +++ b/app/views/commits/compare.html.haml @@ -0,0 +1,49 @@ += render "head" + +%h3 + Compare View +%hr + +%div + %p + Fill input field with commit id like + %code '4eedf23' + or branch/tag name like + %code master + & press compare button for commits list, code diff. + + %br + + = form_tag compare_project_commits_path(@project), :method => :get do + .clearfix + = text_field_tag :from, params[:from], :placeholder => "master", :class => "xlarge" + = "..." + = text_field_tag :to, params[:to], :placeholder => "aa8b4ef", :class => "xlarge" + .actions + = submit_tag "Compare", :class => "btn primary" + + +- unless @commits.empty? + %h4 Commits + %ul.unstyled= render @commits + +- unless @diffs.empty? + %h4 Diff + = render "commits/diffs", :diffs => @diffs + + +:javascript + $(function() { + var availableTags = #{@project.heads.map(&:name).to_json}; + + $( "#from" ).autocomplete({ + source: availableTags, + minLength: 1 + }); + + $( "#to" ).autocomplete({ + source: availableTags, + minLength: 1 + }); + }); + diff --git a/app/views/commits/index.html.haml b/app/views/commits/index.html.haml index 6b6c52d7cc1..a1a5eed796b 100644 --- a/app/views/commits/index.html.haml +++ b/app/views/commits/index.html.haml @@ -1,12 +1,10 @@ += render "head" %h3 Commits - if current_user.private_token %span.rss-icon = link_to project_commits_path(@project, :atom, { :private_token => current_user.private_token, :ref => @ref }) do = image_tag "Rss-UI.PNG", :width => 22, :title => "feed" - = form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form right" do - = select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select" - = hidden_field_tag :destination, "commits" %hr - if params[:path] @@ -31,7 +29,3 @@ CommitsList.init("#{@ref}", 20); }); -:javascript - $(function(){ - $('.project-refs-select').chosen(); - }); diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 05a4c38de5a..28be79bcaf0 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -19,7 +19,7 @@ .clear %br -= render "commits/diff" += render "commits/diffs", :diffs => @commit.diffs = render "notes/notes" = render "notes/per_line_form" diff --git a/app/views/merge_requests/_commits.html.haml b/app/views/merge_requests/_commits.html.haml index ddc0ce19189..baeca7a3aa4 100644 --- a/app/views/merge_requests/_commits.html.haml +++ b/app/views/merge_requests/_commits.html.haml @@ -1,15 +1,6 @@ - if @commits.size > 0 .merge-request-commits - - @commits.each do |commit| - .entry - = link_to project_commit_path(@project, :id => commit.id) do - %strong - = truncate(commit.id.to_s, :length => 10) - = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 - %span= truncate(commit.safe_message, :length => 40) - %span.right - = time_ago_in_words(commit.committed_date) - ago + %ul.unstyled= render @commits - if @commits.empty? %p.cgray Nothing to merge diff --git a/app/views/merge_requests/_diffs.html.haml b/app/views/merge_requests/_diffs.html.haml index 9534da700d3..bd904a77094 100644 --- a/app/views/merge_requests/_diffs.html.haml +++ b/app/views/merge_requests/_diffs.html.haml @@ -1,26 +1,3 @@ -.file_stats - = render "commits/diff_head", :diffs => @diffs -- @diffs.each_with_index do |diff, i| - - next if diff.diff.empty? - - file = (@commit.tree / diff.b_path) - - next unless file - .diff_file - .diff_file_header - - if diff.deleted_file - %strong{:id => "#{diff.b_path}"}= diff.a_path - - else - = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do - %strong{:id => "#{diff.b_path}"}= diff.b_path - %br/ - .diff_file_content - - if file.text? - = render :partial => "commits/text_file", :locals => { :diff => diff, :index => i } - - elsif file.image? - .diff_file_content_image - %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} - - else - %p - %center No preview for this file type - += render "commits/diffs", :diffs => @diffs - if @diffs.empty? %p.cgray Nothing to merge diff --git a/config/routes.rb b/config/routes.rb index 05d96e91d9c..2d818cf39d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,7 +96,11 @@ Gitlab::Application.routes.draw do get :test end end - resources :commits + resources :commits do + collection do + get :compare + end + end resources :team_members resources :issues do collection do diff --git a/spec/requests/commits_spec.rb b/spec/requests/commits_spec.rb index e4195ed8c4a..00b69379848 100644 --- a/spec/requests/commits_spec.rb +++ b/spec/requests/commits_spec.rb @@ -55,4 +55,14 @@ describe "Commits" do current_path.should == project_commit_path(project, commit.id) end end + + describe "GET /commits/compare" do + before do + visit compare_project_commits_path(project) + end + + it "should have valid path" do + current_path.should == compare_project_commits_path(project) + end + end end |