diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-22 17:48:09 +0300 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-12-07 17:01:37 +0300 |
commit | cb6f51ec9b2006f1040cca94119135c92e9a4cd1 (patch) | |
tree | 6331c54f8eab568e134c51ec85a0232372471a16 /lib/gitlab/git.rb | |
parent | 716f9cbb415cd425644b1aeae19844b26cc7d6b7 (diff) |
add support for the commit reference filter
Diffstat (limited to 'lib/gitlab/git.rb')
-rw-r--r-- | lib/gitlab/git.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/gitlab/git.rb b/lib/gitlab/git.rb index 1f31cdbc96d..1f7c35cafaa 100644 --- a/lib/gitlab/git.rb +++ b/lib/gitlab/git.rb @@ -70,6 +70,18 @@ module Gitlab def diff_line_code(file_path, new_line_position, old_line_position) "#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}" end + + def shas_eql?(sha1, sha2) + return false if sha1.nil? || sha2.nil? + return false unless sha1.class == sha2.class + + # If either of the shas is below the minimum length, we cannot be sure + # that they actually refer to the same commit because of hash collision. + length = [sha1.length, sha2.length].min + return false if length < Gitlab::Git::Commit::MIN_SHA_LENGTH + + sha1[0, length] == sha2[0, length] + end end end end |