diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-09-22 11:30:37 +0200 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-09-25 10:22:28 +0200 |
commit | b9857d8b662a2dbbf54f46ecdcecb44702affe55 (patch) | |
tree | 8a25798bc0c8e1c15ae414ac667ff5465f6fefa2 /app/models/commit.rb | |
parent | c19d5ac1a2ac75fd7200aacae3514e5600a7f648 (diff) | |
download | gitlab-ce-b9857d8b662a2dbbf54f46ecdcecb44702affe55.tar.gz |
Properly compare diff refs and diff positions when shas are truncated
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 2ae8890c1b3..c85b5b93607 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -26,7 +26,8 @@ class Commit DIFF_HARD_LIMIT_LINES = 50000 # The SHA can be between 7 and 40 hex characters. - COMMIT_SHA_PATTERN = '\h{7,40}'.freeze + MIN_SHA_LENGTH = 7 + COMMIT_SHA_PATTERN = /\h{#{MIN_SHA_LENGTH},40}/.freeze def banzai_render_context(field) context = { pipeline: :single_line, project: self.project } @@ -53,7 +54,7 @@ class Commit # Truncate sha to 8 characters def truncate_sha(sha) - sha[0..7] + sha[0..MIN_SHA_LENGTH] end def max_diff_options @@ -100,7 +101,7 @@ class Commit def self.reference_pattern @reference_pattern ||= %r{ (?:#{Project.reference_pattern}#{reference_prefix})? - (?<commit>\h{7,40}) + (?<commit>#{COMMIT_SHA_PATTERN}) }x end @@ -216,9 +217,9 @@ class Commit @raw.respond_to?(method, include_private) || super end - # Truncate sha to 8 characters + # Truncate sha to 7 characters def short_id - @raw.short_id(7) + @raw.short_id(MIN_SHA_LENGTH) end def diff_refs |