diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 18:38:44 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-03-03 18:38:44 +0100 |
commit | 1764e1b7cb2bffb9b4c4a69991fe2c4d21ce5459 (patch) | |
tree | b48ca1bad0532a37a19f00f0903a778109a16a3d /app/models/commit.rb | |
parent | e1bc808746523309476913033b104345c06c4816 (diff) | |
download | gitlab-ce-1764e1b7cb2bffb9b4c4a69991fe2c4d21ce5459.tar.gz |
Use Gitlab::Git::DiffCollections
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 3224f5457f0..ce0b85d50cf 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -12,12 +12,7 @@ class Commit attr_accessor :project - # Safe amount of changes (files and lines) in one commit to render - # Used to prevent 500 error on huge commits by suppressing diff - # - # User can force display of diff above this size - DIFF_SAFE_FILES = 100 unless defined?(DIFF_SAFE_FILES) - DIFF_SAFE_LINES = 5000 unless defined?(DIFF_SAFE_LINES) + DIFF_SAFE_LINES = Gitlab::Git::DiffCollection::DEFAULT_LIMITS[:max_lines] # Commits above this size will not be rendered in HTML DIFF_HARD_LIMIT_FILES = 1000 unless defined?(DIFF_HARD_LIMIT_FILES) @@ -36,13 +31,20 @@ class Commit # Calculate number of lines to render for diffs def diff_line_count(diffs) - diffs.reduce(0) { |sum, d| sum + d.diff.lines.count } + diffs.reduce(0) { |sum, d| sum + Gitlab::Git::Util.count_lines(d.diff) } end # Truncate sha to 8 characters def truncate_sha(sha) sha[0..7] end + + def max_diff_options + { + max_files: DIFF_HARD_LIMIT_FILES, + max_lines: DIFF_HARD_LIMIT_LINES, + } + end end attr_accessor :raw |