summaryrefslogtreecommitdiff
path: root/app/views/projects/commits/_diffs.html.haml
blob: aec7f15cdb79e19436a66a33ca4ed475eac3a389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
- @suppress_diff ||= @suppress_diff || @force_suppress_diff
- if @suppress_diff
  .alert.alert-block
    %p
      %strong Warning! This is a large diff.
    %p
      To preserve performance the diff is not shown.
      - if current_controller?(:commit) or current_controller?(:merge_requests)
        Please, download the diff as
        - if current_controller?(:commit)
          = link_to "plain diff", project_commit_path(@project, @commit, format: :diff), class: "underlined_link"
          or
          = link_to "email patch", project_commit_path(@project, @commit, format: :patch), class: "underlined_link"
        - else
          = link_to "plain diff", project_merge_request_path(@project, @merge_request, format: :diff), class: "underlined_link"
          or
          = link_to "email patch", project_merge_request_path(@project, @merge_request, format: :patch), class: "underlined_link"
        instead.
    - unless @force_suppress_diff
      %p
        If you still want to see the diff
        = link_to "click this link", url_for(force_show_diff: true), class: "underlined_link"

%p.commit-stat-summary
  Showing
  %strong.cdark #{pluralize(diffs.count, "changed file")}
  - if current_controller?(:commit)
    - unless @commit.has_zero_stats?
      with
      %strong.cgreen #{@commit.stats.additions} additions
      and
      %strong.cred #{@commit.stats.deletions} deletions
  - if params[:view] == 'parallel'
    = link_to "Unified Diff", url_for(view: 'unified'), {id: "commit-diff-viewtype", class: 'btn btn-tiny pull-right'}
  - else
    = link_to "Parallel Diff", url_for(view: 'parallel'), {id: "commit-diff-viewtype", class: 'btn btn-tiny pull-right'}
.file-stats
  = render "projects/commits/diff_head", diffs: diffs

.files
  - unless @suppress_diff
    - diffs.each_with_index do |diff, i|
      - next if diff.diff.empty?
      - file = project.repository.blob_at(@commit.id, diff.new_path)
      - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
      - next unless file
      .file{id: "diff-#{i}"}
        .header
          - if diff.deleted_file
            %span= diff.old_path

            - if @commit.parent_ids.present?
              = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
                View file @
                %span.commit-short-id= @commit.short_id(6)
          - else
            %span= diff.new_path
            - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode
              %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}"

            = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
              View file @
              %span.commit-short-id= @commit.short_id(6)

        .content
          -# Skipp all non non-supported blobs
          - next unless file.respond_to?('text?')
          - if file.text?
            - if params[:view] == 'parallel'
              = render "projects/commits/parallel_view", diff: diff, project: project, file: file, index: i            
            - else
              = render "projects/commits/text_file", diff: diff, index: i
          - elsif file.image?
            - old_file = project.repository.blob_at(@commit.parent_id, diff.old_path) if @commit.parent_id
            = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
          - else
            %p.nothing_here_message No preview for this file type