diff --git a/app/assets/stylesheets/commits.css.scss b/app/assets/stylesheets/commits.css.scss index 05630f7..691b3d8 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 e2853dd..73d28a5 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 0000000..c2a8c97 --- /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 cdea9ac..1394207 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/_diff.html.haml deleted file mode 100644 index cf5ef60..0000000 --- a/app/views/commits/_diff.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -.file_stats - = render "commits/diff_head", :diffs => @commit.diffs - -- @commit.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 diff --git a/app/views/commits/_diffs.html.haml b/app/views/commits/_diffs.html.haml new file mode 100644 index 0000000..8f65afc --- /dev/null +++ b/app/views/commits/_diffs.html.haml @@ -0,0 +1,25 @@ +.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 + diff --git a/app/views/commits/_head.html.haml b/app/views/commits/_head.html.haml new file mode 100644 index 0000000..f6facea --- /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 0000000..877bd40 --- /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 6b6c52d..a1a5eed 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 05a4c38..28be79b 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 ddc0ce1..baeca7a 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 9534da7..bd904a7 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 05d96e9..2d818cf 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 e4195ed..00b6937 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 -- libgit2 0.21.2