summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb54
1 files changed, 29 insertions, 25 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index dd1f9801878..c313aeb7572 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -16,29 +16,31 @@ class Commit
DIFF_HARD_LIMIT_FILES = 500
DIFF_HARD_LIMIT_LINES = 10000
- def self.decorate(commits)
- commits.map { |c| self.new(c) }
- end
+ class << self
+ def decorate(commits)
+ commits.map { |c| self.new(c) }
+ end
- # Calculate number of lines to render for diffs
- def self.diff_line_count(diffs)
- diffs.reduce(0){|sum, d| sum + d.diff.lines.count}
- end
+ # Calculate number of lines to render for diffs
+ def diff_line_count(diffs)
+ diffs.reduce(0){|sum, d| sum + d.diff.lines.count}
+ end
- def self.diff_suppress?(diffs, line_count = nil)
- # optimize - check file count first
- return true if diffs.size > DIFF_SAFE_FILES
+ def diff_suppress?(diffs, line_count = nil)
+ # optimize - check file count first
+ return true if diffs.size > DIFF_SAFE_FILES
- line_count ||= Commit::diff_line_count(diffs)
- line_count > DIFF_SAFE_LINES
- end
+ line_count ||= Commit::diff_line_count(diffs)
+ line_count > DIFF_SAFE_LINES
+ end
- def self.diff_force_suppress?(diffs, line_count = nil)
- # optimize - check file count first
- return true if diffs.size > DIFF_HARD_LIMIT_FILES
+ def diff_force_suppress?(diffs, line_count = nil)
+ # optimize - check file count first
+ return true if diffs.size > DIFF_HARD_LIMIT_FILES
- line_count ||= Commit::diff_line_count(diffs)
- line_count > DIFF_HARD_LIMIT_LINES
+ line_count ||= Commit::diff_line_count(diffs)
+ line_count > DIFF_HARD_LIMIT_LINES
+ end
end
attr_accessor :raw
@@ -97,14 +99,16 @@ class Commit
#
# cut off, ellipses (`&hellp;`) are prepended to the commit message.
def description
- description = safe_message
+ title_end = safe_message.index(/\n/)
+ @description ||= if (!title_end && safe_message.length > 100) || (title_end && title_end > 100)
+ "&hellip;".html_safe << safe_message[80..-1]
+ else
+ safe_message.split(/\n/, 2)[1].try(:chomp)
+ end
+ end
- title_end = description.index(/\n/)
- if (!title_end && description.length > 100) || (title_end && title_end > 100)
- "&hellip;".html_safe << description[80..-1]
- else
- description.split(/\n/, 2)[1].try(:chomp)
- end
+ def description?
+ description.present?
end
# Regular expression that identifies commit message clauses that trigger issue closing.