summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-08-03 09:08:24 +0100
committerPhil Hughes <me@iamphill.com>2016-08-03 09:08:24 +0100
commita45071d0ea18d9bb8a5209ef97e4858dda08cd33 (patch)
treed9f8e538c5c0e6ef2e25acf2520f31a419b34ec8 /app/models/commit.rb
parente5b64f20c730bd6e18af694b2c1503020ba1db51 (diff)
parente63729d9e70a661fb3fb8cb558716f6a44a52798 (diff)
downloadgitlab-ce-a45071d0ea18d9bb8a5209ef97e4858dda08cd33.tar.gz
Merge branch 'master' into ref-switcher-enter-submit
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb35
1 files changed, 26 insertions, 9 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 2ef3973c160..c52b4a051c2 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -123,15 +123,17 @@ class Commit
# In case this first line is longer than 100 characters, it is cut off
# after 80 characters and ellipses (`&hellp;`) are appended.
def title
- title = safe_message
+ full_title.length > 100 ? full_title[0..79] << "…" : full_title
+ end
- return no_commit_message if title.blank?
+ # Returns the full commits title
+ def full_title
+ return @full_title if @full_title
- title_end = title.index("\n")
- if (!title_end && title.length > 100) || (title_end && title_end > 100)
- title[0..79] << "…"
+ if safe_message.blank?
+ @full_title = no_commit_message
else
- title.split("\n", 2).first
+ @full_title = safe_message.split("\n", 2).first
end
end
@@ -178,7 +180,18 @@ class Commit
end
def author
- @author ||= User.find_by_any_email(author_email.downcase)
+ if RequestStore.active?
+ key = "commit_author:#{author_email.downcase}"
+ # nil is a valid value since no author may exist in the system
+ if RequestStore.store.has_key?(key)
+ @author = RequestStore.store[key]
+ else
+ @author = find_author_by_any_email
+ RequestStore.store[key] = @author
+ end
+ else
+ @author ||= find_author_by_any_email
+ end
end
def committer
@@ -295,8 +308,8 @@ class Commit
def uri_type(path)
entry = @raw.tree.path(path)
if entry[:type] == :blob
- blob = Gitlab::Git::Blob.new(name: entry[:name])
- blob.image? ? :raw : :blob
+ blob = ::Blob.decorate(Gitlab::Git::Blob.new(name: entry[:name]))
+ blob.image? || blob.video? ? :raw : :blob
else
entry[:type]
end
@@ -306,6 +319,10 @@ class Commit
private
+ def find_author_by_any_email
+ User.find_by_any_email(author_email.downcase)
+ end
+
def repo_changes
changes = { added: [], modified: [], removed: [] }