Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/commit_range.rb25
-rw-r--r--spec/models/commit_range_spec.rb4
2 files changed, 13 insertions, 16 deletions
diff --git a/app/models/commit_range.rb b/app/models/commit_range.rb
index b3712aed056..19b1a218e45 100644
--- a/app/models/commit_range.rb
+++ b/app/models/commit_range.rb
@@ -45,12 +45,10 @@ class CommitRange
raise ArgumentError, "invalid CommitRange string format: #{range_string}"
end
- @inclusive = range_string !~ /\.{3}/
+ @inclusive = !range_string.include?('...')
@sha_from, @notation, @sha_to = range_string.split(/(\.{2,3})/, 2)
@project = project
-
- @_commit_map = {}
end
def inspect
@@ -63,7 +61,7 @@ class CommitRange
# Returns `[nil, nil]` if `valid_commits?` is falsey
def to_a
if valid_commits?
- [commit(sha_from), commit(sha_to)]
+ [commit_from, commit_to]
else
[nil, nil]
end
@@ -104,25 +102,24 @@ class CommitRange
return nil unless project.present?
return false unless project.valid_repo?
- commit(sha_from).present? && commit(sha_to).present?
+ commit_from.present? && commit_to.present?
end
def persisted?
true
end
- private
+ def commit_from
+ @commit_from ||= project.repository.commit(sha_from_as_param)
+ end
- def sha_from_as_param
- sha_from + (inclusive? ? '^' : '')
+ def commit_to
+ @commit_to ||= project.repository.commit(sha_to)
end
- def commit(sha)
- unless @_commit_map[sha]
- # FIXME (rspeicher): Law of Demeter
- @_commit_map[sha] = project.repository.commit(sha)
- end
+ private
- @_commit_map[sha]
+ def sha_from_as_param
+ sha_from + (inclusive? ? '^' : '')
end
end
diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb
index 2d1c1bd1049..474d60ff091 100644
--- a/spec/models/commit_range_spec.rb
+++ b/spec/models/commit_range_spec.rb
@@ -18,8 +18,8 @@ describe CommitRange do
before do
expect(range).to receive(:valid_commits?).and_return(true)
- allow(range).to receive(:commit).with(sha_from).and_return(commit1)
- allow(range).to receive(:commit).with(sha_to).and_return(commit2)
+ allow(range).to receive(:commit_from).and_return(commit1)
+ allow(range).to receive(:commit_to).and_return(commit2)
end
it 'returns an Array of Commits' do