Commit 422e43989b0e35f3773c7e91f3d04c0baec0fb14
1 parent
6c416aaa
Exists in
master
and in
4 other branches
Compare view for commits
Showing
14 changed files
with
157 additions
and
83 deletions
Show diff stats
app/assets/stylesheets/commits.css.scss
app/controllers/commits_controller.rb
... | ... | @@ -9,6 +9,7 @@ class CommitsController < ApplicationController |
9 | 9 | before_filter :authorize_read_project! |
10 | 10 | before_filter :require_non_empty_project |
11 | 11 | before_filter :load_refs, :only => :index # load @branch, @tag & @ref |
12 | + before_filter :render_full_content | |
12 | 13 | |
13 | 14 | def index |
14 | 15 | @repo = project.repo |
... | ... | @@ -29,11 +30,29 @@ class CommitsController < ApplicationController |
29 | 30 | |
30 | 31 | @line_notes = project.commit_line_notes(@commit) |
31 | 32 | |
32 | - render_full_content | |
33 | - | |
34 | 33 | respond_to do |format| |
35 | 34 | format.html |
36 | 35 | format.js { respond_with_notes } |
37 | 36 | end |
38 | 37 | end |
38 | + | |
39 | + def compare | |
40 | + first = project.commit(params[:to]) | |
41 | + last = project.commit(params[:from]) | |
42 | + | |
43 | + @diffs = [] | |
44 | + @commits = [] | |
45 | + @line_notes = [] | |
46 | + | |
47 | + if first && last | |
48 | + commits = [first, last].sort_by(&:created_at) | |
49 | + younger = commits.first | |
50 | + older = commits.last | |
51 | + | |
52 | + | |
53 | + @commits = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} | |
54 | + @diffs = project.repo.diff(younger.id, older.id) rescue [] | |
55 | + @commit = older | |
56 | + end | |
57 | + end | |
39 | 58 | end | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +%li.entry | |
2 | + = link_to project_commit_path(@project, :id => commit.id) do | |
3 | + %div | |
4 | + %strong | |
5 | + = truncate commit.id.to_s, :length => 10 | |
6 | + – | |
7 | + = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 | |
8 | + = truncate(commit.safe_message, :length => 50) | |
9 | + | |
10 | + %span.right.cgray | |
11 | + = time_ago_in_words(commit.committed_date) | |
12 | + ago | |
13 | + | ... | ... |
app/views/commits/_commits.html.haml
... | ... | @@ -3,17 +3,4 @@ |
3 | 3 | .day-commits-table |
4 | 4 | %h5.underlined= day.stamp("28 Aug, 2010") |
5 | 5 | %br |
6 | - %ul.unstyled | |
7 | - - commits.each do |commit| | |
8 | - %li.entry | |
9 | - = link_to project_commit_path(@project, :id => commit.id) do | |
10 | - %div | |
11 | - %strong | |
12 | - = truncate commit.id.to_s, :length => 10 | |
13 | - – | |
14 | - = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 | |
15 | - = truncate(commit.safe_message, :length => 50) | |
16 | - | |
17 | - %span.right.cgray | |
18 | - = time_ago_in_words(commit.committed_date) | |
19 | - ago | |
6 | + %ul.unstyled= render commits | ... | ... |
app/views/commits/_diff.html.haml
... | ... | @@ -1,24 +0,0 @@ |
1 | -.file_stats | |
2 | - = render "commits/diff_head", :diffs => @commit.diffs | |
3 | - | |
4 | -- @commit.diffs.each_with_index do |diff, i| | |
5 | - - next if diff.diff.empty? | |
6 | - - file = (@commit.tree / diff.b_path) | |
7 | - - next unless file | |
8 | - .diff_file | |
9 | - .diff_file_header | |
10 | - - if diff.deleted_file | |
11 | - %strong{:id => "#{diff.b_path}"}= diff.a_path | |
12 | - - else | |
13 | - = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do | |
14 | - %strong{:id => "#{diff.b_path}"}= diff.b_path | |
15 | - %br/ | |
16 | - .diff_file_content | |
17 | - - if file.text? | |
18 | - = render :partial => "commits/text_file", :locals => { :diff => diff, :index => i } | |
19 | - - elsif file.image? | |
20 | - .diff_file_content_image | |
21 | - %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | |
22 | - - else | |
23 | - %p | |
24 | - %center No preview for this file type |
... | ... | @@ -0,0 +1,25 @@ |
1 | +.file_stats | |
2 | + = render "commits/diff_head", :diffs => diffs | |
3 | + | |
4 | +- diffs.each_with_index do |diff, i| | |
5 | + - next if diff.diff.empty? | |
6 | + - file = (@commit.tree / diff.b_path) | |
7 | + - next unless file | |
8 | + .diff_file | |
9 | + .diff_file_header | |
10 | + - if diff.deleted_file | |
11 | + %strong{:id => "#{diff.b_path}"}= diff.a_path | |
12 | + - else | |
13 | + = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do | |
14 | + %strong{:id => "#{diff.b_path}"}= diff.b_path | |
15 | + %br/ | |
16 | + .diff_file_content | |
17 | + - if file.text? | |
18 | + = render :partial => "commits/text_file", :locals => { :diff => diff, :index => i } | |
19 | + - elsif file.image? | |
20 | + .diff_file_content_image | |
21 | + %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | |
22 | + - else | |
23 | + %p | |
24 | + %center No preview for this file type | |
25 | + | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +%ul.tabs | |
2 | + %li | |
3 | + = form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form commit-refs-form" do | |
4 | + = select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select" | |
5 | + = hidden_field_tag :destination, "commits" | |
6 | + | |
7 | + %li{:class => "#{'active' if current_page?(project_commits_path(@project)) }"} | |
8 | + = link_to project_commits_path(@project) do | |
9 | + %span | |
10 | + Commits | |
11 | + %li{:class => "#{'active' if current_page?(compare_project_commits_path(@project)) }"} | |
12 | + = link_to compare_project_commits_path(@project) do | |
13 | + %span | |
14 | + Compare | |
15 | + | |
16 | + | |
17 | + | |
18 | + | |
19 | +:javascript | |
20 | + $(function(){ | |
21 | + $('.project-refs-select').chosen(); | |
22 | + }); | ... | ... |
... | ... | @@ -0,0 +1,49 @@ |
1 | += render "head" | |
2 | + | |
3 | +%h3 | |
4 | + Compare View | |
5 | +%hr | |
6 | + | |
7 | +%div | |
8 | + %p | |
9 | + Fill input field with commit id like | |
10 | + %code '4eedf23' | |
11 | + or branch/tag name like | |
12 | + %code master | |
13 | + & press compare button for commits list, code diff. | |
14 | + | |
15 | + %br | |
16 | + | |
17 | + = form_tag compare_project_commits_path(@project), :method => :get do | |
18 | + .clearfix | |
19 | + = text_field_tag :from, params[:from], :placeholder => "master", :class => "xlarge" | |
20 | + = "..." | |
21 | + = text_field_tag :to, params[:to], :placeholder => "aa8b4ef", :class => "xlarge" | |
22 | + .actions | |
23 | + = submit_tag "Compare", :class => "btn primary" | |
24 | + | |
25 | + | |
26 | +- unless @commits.empty? | |
27 | + %h4 Commits | |
28 | + %ul.unstyled= render @commits | |
29 | + | |
30 | +- unless @diffs.empty? | |
31 | + %h4 Diff | |
32 | + = render "commits/diffs", :diffs => @diffs | |
33 | + | |
34 | + | |
35 | +:javascript | |
36 | + $(function() { | |
37 | + var availableTags = #{@project.heads.map(&:name).to_json}; | |
38 | + | |
39 | + $( "#from" ).autocomplete({ | |
40 | + source: availableTags, | |
41 | + minLength: 1 | |
42 | + }); | |
43 | + | |
44 | + $( "#to" ).autocomplete({ | |
45 | + source: availableTags, | |
46 | + minLength: 1 | |
47 | + }); | |
48 | + }); | |
49 | + | ... | ... |
app/views/commits/index.html.haml
1 | += render "head" | |
1 | 2 | %h3 |
2 | 3 | Commits |
3 | 4 | - if current_user.private_token |
4 | 5 | %span.rss-icon |
5 | 6 | = link_to project_commits_path(@project, :atom, { :private_token => current_user.private_token, :ref => @ref }) do |
6 | 7 | = image_tag "Rss-UI.PNG", :width => 22, :title => "feed" |
7 | - = form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form right" do | |
8 | - = select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select" | |
9 | - = hidden_field_tag :destination, "commits" | |
10 | 8 | %hr |
11 | 9 | |
12 | 10 | - if params[:path] |
... | ... | @@ -31,7 +29,3 @@ |
31 | 29 | CommitsList.init("#{@ref}", 20); |
32 | 30 | }); |
33 | 31 | |
34 | -:javascript | |
35 | - $(function(){ | |
36 | - $('.project-refs-select').chosen(); | |
37 | - }); | ... | ... |
app/views/commits/show.html.haml
app/views/merge_requests/_commits.html.haml
1 | 1 | - if @commits.size > 0 |
2 | 2 | .merge-request-commits |
3 | - - @commits.each do |commit| | |
4 | - .entry | |
5 | - = link_to project_commit_path(@project, :id => commit.id) do | |
6 | - %strong | |
7 | - = truncate(commit.id.to_s, :length => 10) | |
8 | - = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 | |
9 | - %span= truncate(commit.safe_message, :length => 40) | |
10 | - %span.right | |
11 | - = time_ago_in_words(commit.committed_date) | |
12 | - ago | |
3 | + %ul.unstyled= render @commits | |
13 | 4 | |
14 | 5 | - if @commits.empty? |
15 | 6 | %p.cgray Nothing to merge | ... | ... |
app/views/merge_requests/_diffs.html.haml
1 | -.file_stats | |
2 | - = render "commits/diff_head", :diffs => @diffs | |
3 | -- @diffs.each_with_index do |diff, i| | |
4 | - - next if diff.diff.empty? | |
5 | - - file = (@commit.tree / diff.b_path) | |
6 | - - next unless file | |
7 | - .diff_file | |
8 | - .diff_file_header | |
9 | - - if diff.deleted_file | |
10 | - %strong{:id => "#{diff.b_path}"}= diff.a_path | |
11 | - - else | |
12 | - = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do | |
13 | - %strong{:id => "#{diff.b_path}"}= diff.b_path | |
14 | - %br/ | |
15 | - .diff_file_content | |
16 | - - if file.text? | |
17 | - = render :partial => "commits/text_file", :locals => { :diff => diff, :index => i } | |
18 | - - elsif file.image? | |
19 | - .diff_file_content_image | |
20 | - %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | |
21 | - - else | |
22 | - %p | |
23 | - %center No preview for this file type | |
24 | - | |
1 | += render "commits/diffs", :diffs => @diffs | |
25 | 2 | - if @diffs.empty? |
26 | 3 | %p.cgray Nothing to merge | ... | ... |
config/routes.rb
spec/requests/commits_spec.rb
... | ... | @@ -55,4 +55,14 @@ describe "Commits" do |
55 | 55 | current_path.should == project_commit_path(project, commit.id) |
56 | 56 | end |
57 | 57 | end |
58 | + | |
59 | + describe "GET /commits/compare" do | |
60 | + before do | |
61 | + visit compare_project_commits_path(project) | |
62 | + end | |
63 | + | |
64 | + it "should have valid path" do | |
65 | + current_path.should == compare_project_commits_path(project) | |
66 | + end | |
67 | + end | |
58 | 68 | end | ... | ... |