Commit 422e4398 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Compare view for commits

parent 6c416aaa
......@@ -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;
}
......@@ -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
%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
......@@ -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
&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
%ul.unstyled= render commits
.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
%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();
});
= 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
});
});
= 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();
});
......@@ -19,7 +19,7 @@
.clear
%br
= render "commits/diff"
= render "commits/diffs", :diffs => @commit.diffs
= render "notes/notes"
= render "notes/per_line_form"
......
- 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
.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
......@@ -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
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment