Compare view for commits

This commit is contained in:
Dmitriy Zaporozhets 2012-02-06 22:32:04 +02:00
parent 6c416aaac8
commit 422e43989b
13 changed files with 135 additions and 61 deletions

View file

@ -134,3 +134,10 @@ ul.bordered-list li:last-child { border:none }
margin:2px; margin:2px;
} }
} }
.project-refs-form.commit-refs-form .chzn-container {
position: relative;
top: 0;
left: 0;
margin-right: 10px;
}

View file

@ -9,6 +9,7 @@ class CommitsController < ApplicationController
before_filter :authorize_read_project! before_filter :authorize_read_project!
before_filter :require_non_empty_project before_filter :require_non_empty_project
before_filter :load_refs, :only => :index # load @branch, @tag & @ref before_filter :load_refs, :only => :index # load @branch, @tag & @ref
before_filter :render_full_content
def index def index
@repo = project.repo @repo = project.repo
@ -29,11 +30,29 @@ class CommitsController < ApplicationController
@line_notes = project.commit_line_notes(@commit) @line_notes = project.commit_line_notes(@commit)
render_full_content
respond_to do |format| respond_to do |format|
format.html format.html
format.js { respond_with_notes } format.js { respond_with_notes }
end end
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 end

View file

@ -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
&ndash;
= 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

View file

@ -3,17 +3,4 @@
.day-commits-table .day-commits-table
%h5.underlined= day.stamp("28 Aug, 2010") %h5.underlined= day.stamp("28 Aug, 2010")
%br %br
%ul.unstyled %ul.unstyled= render commits
- 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
&ndash;
= 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

View file

@ -1,7 +1,7 @@
.file_stats .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? - next if diff.diff.empty?
- file = (@commit.tree / diff.b_path) - file = (@commit.tree / diff.b_path)
- next unless file - next unless file
@ -22,3 +22,4 @@
- else - else
%p %p
%center No preview for this file type %center No preview for this file type

View file

@ -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();
});

View file

@ -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
&amp; 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
});
});

View file

@ -1,12 +1,10 @@
= render "head"
%h3 %h3
Commits Commits
- if current_user.private_token - if current_user.private_token
%span.rss-icon %span.rss-icon
= link_to project_commits_path(@project, :atom, { :private_token => current_user.private_token, :ref => @ref }) do = 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" = 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 %hr
- if params[:path] - if params[:path]
@ -31,7 +29,3 @@
CommitsList.init("#{@ref}", 20); CommitsList.init("#{@ref}", 20);
}); });
:javascript
$(function(){
$('.project-refs-select').chosen();
});

View file

@ -19,7 +19,7 @@
.clear .clear
%br %br
= render "commits/diff" = render "commits/diffs", :diffs => @commit.diffs
= render "notes/notes" = render "notes/notes"
= render "notes/per_line_form" = render "notes/per_line_form"

View file

@ -1,15 +1,6 @@
- if @commits.size > 0 - if @commits.size > 0
.merge-request-commits .merge-request-commits
- @commits.each do |commit| %ul.unstyled= render @commits
.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
- if @commits.empty? - if @commits.empty?
%p.cgray Nothing to merge %p.cgray Nothing to merge

View file

@ -1,26 +1,3 @@
.file_stats = render "commits/diffs", :diffs => @diffs
= 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
- if @diffs.empty? - if @diffs.empty?
%p.cgray Nothing to merge %p.cgray Nothing to merge

View file

@ -96,7 +96,11 @@ Gitlab::Application.routes.draw do
get :test get :test
end end
end end
resources :commits resources :commits do
collection do
get :compare
end
end
resources :team_members resources :team_members
resources :issues do resources :issues do
collection do collection do

View file

@ -55,4 +55,14 @@ describe "Commits" do
current_path.should == project_commit_path(project, commit.id) current_path.should == project_commit_path(project, commit.id)
end end
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 end