summaryrefslogtreecommitdiff
path: root/app/models/commit_range.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/commit_range.rb')
-rw-r--r--app/models/commit_range.rb30
1 files changed, 28 insertions, 2 deletions
diff --git a/app/models/commit_range.rb b/app/models/commit_range.rb
index e6456198264..86fc9eb01a3 100644
--- a/app/models/commit_range.rb
+++ b/app/models/commit_range.rb
@@ -19,6 +19,7 @@
#
class CommitRange
include ActiveModel::Conversion
+ include Referable
attr_reader :sha_from, :notation, :sha_to
@@ -28,10 +29,24 @@ class CommitRange
# See `exclude_start?`
attr_reader :exclude_start
- # The beginning and ending SHA sums can be between 6 and 40 hex characters,
- # and the range selection can be double- or triple-dot.
+ # The beginning and ending SHAs can be between 6 and 40 hex characters, and
+ # the range notation can be double- or triple-dot.
PATTERN = /\h{6,40}\.{2,3}\h{6,40}/
+ def self.reference_prefix
+ '@'
+ end
+
+ # Pattern used to extract commit range references from text
+ #
+ # This pattern supports cross-project references.
+ def self.reference_pattern
+ %r{
+ (?:#{Project.reference_pattern}#{reference_prefix})?
+ (?<commit_range>#{PATTERN})
+ }x
+ end
+
# Initialize a CommitRange
#
# range_string - The String commit range.
@@ -59,6 +74,17 @@ class CommitRange
"#{sha_from[0..7]}#{notation}#{sha_to[0..7]}"
end
+ def to_reference(from_project = nil)
+ # Not using to_s because we want the full SHAs
+ reference = sha_from + notation + sha_to
+
+ if cross_project_reference?(from_project)
+ reference = project.to_reference + '@' + reference
+ end
+
+ reference
+ end
+
# Returns a String for use in a link's title attribute
def reference_title
"Commits #{suffixed_sha_from} through #{sha_to}"