From 38cd3d64514655c508eba980b7abc216ef2a1c0b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 2 May 2015 22:41:37 -0400 Subject: Add Commit#== Prior, comparison would use the Ruby object's ID, which got out of sync after a Spring fork and would result in erroneous test failures. Now we just check that the compared object is a Commit and then compare their underlying raw commit objects. --- app/models/commit.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index be5a118bfec..5dea7dda513 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -56,6 +56,10 @@ class Commit @raw.id end + def ==(other) + (self.class === other) && (raw == other.raw) + end + def diff_line_count @diff_line_count ||= Commit::diff_line_count(self.diffs) @diff_line_count -- cgit v1.2.1 From c0faf91ff23815404a95cf4510b43dcf5e331c4f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 2 May 2015 23:11:21 -0400 Subject: Add `to_reference` for models that support references Now there is a single source of information for which attribute a model uses to be referenced, and its special character. --- app/models/commit.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 5dea7dda513..3cc8d11a4aa 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -1,9 +1,11 @@ class Commit - include ActiveModel::Conversion - include StaticModel extend ActiveModel::Naming + + include ActiveModel::Conversion include Mentionable include Participable + include Referable + include StaticModel attr_mentionable :safe_message participant :author, :committer, :notes, :mentioned_users @@ -60,6 +62,14 @@ class Commit (self.class === other) && (raw == other.raw) end + def to_reference(from_project = nil) + if cross_project_reference?(from_project) + "#{project.to_reference}@#{id}" + else + id + end + end + def diff_line_count @diff_line_count ||= Commit::diff_line_count(self.diffs) @diff_line_count @@ -132,7 +142,7 @@ class Commit # Mentionable override. def gfm_reference - "commit #{id}" + "commit #{to_reference}" end def author -- cgit v1.2.1 From 0359d41b064e9f7680d0017013e011103747b614 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 11 May 2015 15:56:00 -0400 Subject: Implement gfm_reference directly in Mentionable Except for Note, which still overrides it. --- app/models/commit.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 3cc8d11a4aa..085f4e6398f 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -140,11 +140,6 @@ class Commit Gitlab::ClosingIssueExtractor.new(project, current_user).closed_by_message(safe_message) end - # Mentionable override. - def gfm_reference - "commit #{to_reference}" - end - def author User.find_for_commit(author_email, author_name) end -- cgit v1.2.1 From b88da58cb6272a86b6df2e4efe392f10e689a6b2 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 14 May 2015 16:59:39 -0400 Subject: Add `reference_pattern` to Referable models --- app/models/commit.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 085f4e6398f..2c244fc0410 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -62,6 +62,19 @@ class Commit (self.class === other) && (raw == other.raw) end + def self.reference_prefix + '@' + end + + # Pattern used to extract commit references from text + # + # The SHA can be between 6 and 40 hex characters. + # + # This pattern supports cross-project references. + def self.reference_pattern + %r{(?:#{Project.reference_pattern}#{reference_prefix})?(?\h{6,40})} + end + def to_reference(from_project = nil) if cross_project_reference?(from_project) "#{project.to_reference}@#{id}" -- cgit v1.2.1 From 1a9da9178cfd25190997b621e428a5c7ce467cd1 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 15 May 2015 16:10:55 -0400 Subject: Surround Project.reference_pattern in parenthesis inside other patterns --- app/models/commit.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 2c244fc0410..f02fe240540 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -72,7 +72,10 @@ class Commit # # This pattern supports cross-project references. def self.reference_pattern - %r{(?:#{Project.reference_pattern}#{reference_prefix})?(?\h{6,40})} + %r{ + (?:#{Project.reference_pattern}#{reference_prefix})? + (?\h{6,40}) + }x end def to_reference(from_project = nil) -- cgit v1.2.1