summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2014-10-12 20:28:21 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2014-10-12 20:28:21 +0000
commitb956605f9e5f95ded853d3458f0f132dbb5b892a (patch)
treedd1596c99ab5766e8749f45acb1e5a0d22e1a4d1 /app/models/commit.rb
parent66dd61ef0f1f98f860bdef5aa2cdb1c6f2e1f83f (diff)
parentb02c21df5cc0dcc795f71f8c11d05d61dc2ad897 (diff)
downloadgitlab-ce-fondev.tar.gz
Merge branch 'ambiguous-sha' into 'master'fondev
Fix ambiguous sha problem with mentioned commit Before: write in database only 6 chars of commit sha. This cause to `Ambiguous SHA1 prefix` exception. - [x] write full commit sha in db. - [x] Standardise usage of sha truncation: 8 characters everywhere. - [x] prevent exception when ambiguous sha requested in markdown Fixes #1644 See merge request !1171
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index a1343b65c72..212229649fc 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -19,13 +19,24 @@ class Commit
class << self
def decorate(commits)
- commits.map { |c| self.new(c) }
+ commits.map do |commit|
+ if commit.kind_of?(Commit)
+ commit
+ else
+ self.new(commit)
+ end
+ end
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
+
+ # Truncate sha to 8 characters
+ def truncate_sha(sha)
+ sha[0..7]
+ end
end
attr_accessor :raw
@@ -111,7 +122,7 @@ class Commit
# Mentionable override.
def gfm_reference
- "commit #{sha[0..5]}"
+ "commit #{id}"
end
def method_missing(m, *args, &block)
@@ -124,6 +135,11 @@ class Commit
super
end
+ # Truncate sha to 8 characters
+ def short_id
+ @raw.short_id(7)
+ end
+
def parents
@parents ||= Commit.decorate(super)
end