Commit 0a6b64e6a9c5858801a7af2c408416b1c98de471

Authored by Dmitriy Zaporozhets
1 parent d40b9ce2

MR: Handle broken diff ex. in case its too huge

app/models/merge_request.rb
... ... @@ -3,6 +3,8 @@ require File.join(Rails.root, "app/models/commit")
3 3 class MergeRequest < ActiveRecord::Base
4 4 include Upvote
5 5  
  6 + BROKEN_DIFF = "--broken-diff"
  7 +
6 8 UNCHECKED = 1
7 9 CAN_BE_MERGED = 2
8 10 CANNOT_BE_MERGED = 3
... ... @@ -108,14 +110,25 @@ class MergeRequest &lt; ActiveRecord::Base
108 110 def reloaded_diffs
109 111 if open? && unmerged_diffs.any?
110 112 self.st_diffs = unmerged_diffs
111   - save
  113 + self.save
112 114 end
113   - diffs
  115 +
  116 + rescue Grit::Git::GitTimeout
  117 + self.st_diffs = [BROKEN_DIFF]
  118 + self.save
  119 + end
  120 +
  121 + def broken_diffs?
  122 + diffs == [BROKEN_DIFF]
  123 + end
  124 +
  125 + def valid_diffs?
  126 + !broken_diffs?
114 127 end
115 128  
116 129 def unmerged_diffs
117 130 commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
118   - diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue []
  131 + diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id)
119 132 end
120 133  
121 134 def last_commit
... ...
app/views/layouts/_project_menu.html.haml
... ... @@ -13,24 +13,25 @@
13 13 %li{:class => tab_class(:network)}
14 14 = link_to "Network", graph_project_path(@project)
15 15  
16   - - if @project.issues_enabled
17   - %li{:class => tab_class(:issues)}
18   - = link_to project_issues_filter_path(@project) do
19   - Issues
20   - %span.count= @project.issues.opened.count
  16 + - if @project.issues_enabled
  17 + %li{:class => tab_class(:issues)}
  18 + = link_to project_issues_filter_path(@project) do
  19 + Issues
  20 + %span.count= @project.issues.opened.count
21 21  
  22 + - if @project.repo_exists?
22 23 - if @project.merge_requests_enabled
23 24 %li{:class => tab_class(:merge_requests)}
24 25 = link_to project_merge_requests_path(@project) do
25 26 Merge Requests
26 27 %span.count= @project.merge_requests.opened.count
27 28  
28   - - if @project.wall_enabled
29   - %li{:class => tab_class(:wall)}
30   - = link_to wall_project_path(@project) do
31   - Wall
  29 + - if @project.wall_enabled
  30 + %li{:class => tab_class(:wall)}
  31 + = link_to wall_project_path(@project) do
  32 + Wall
32 33  
33   - - if @project.wiki_enabled
34   - %li{:class => tab_class(:wiki)}
35   - = link_to project_wiki_path(@project, :index) do
36   - Wiki
  34 + - if @project.wiki_enabled
  35 + %li{:class => tab_class(:wiki)}
  36 + = link_to project_wiki_path(@project, :index) do
  37 + Wiki
... ...
app/views/merge_requests/show/_diffs.html.haml
1   -= render "commits/diffs", :diffs => @diffs
2   -- if @diffs.empty?
3   - %p.cgray Nothing to merge
  1 +- if @merge_request.valid_diffs?
  2 + = render "commits/diffs", :diffs => @diffs
  3 +- elsif @merge_request.broken_diffs?
  4 + %h4.nothing_here_message
  5 + Can't load diff.
  6 + You can #{link_to "download MR patch", raw_project_merge_request_path(@project, @merge_request), :class => "vlink"} instead.
  7 +- else
  8 + %h4.nothing_here_message Nothing to merge
... ...