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:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-12 13:27:59 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-12 16:32:57 +0300
commitb48c4b2662e7db9d68052392fb34dd2b27d12cf5 (patch)
tree7a2c3aa891ed8f8de411c85f3d00d2a82726384b /app/models/compare.rb
parent7421c08ace8a129b37c4942eb21a0b5cf1a73a53 (diff)
Refactor straight compare diff code
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/compare.rb')
-rw-r--r--app/models/compare.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/app/models/compare.rb b/app/models/compare.rb
index 4b568a1d11c..3a8bbcb1acd 100644
--- a/app/models/compare.rb
+++ b/app/models/compare.rb
@@ -11,7 +11,7 @@ class Compare
end
end
- def initialize(compare, project, straight = false)
+ def initialize(compare, project, straight: false)
@compare = compare
@project = project
@straight = straight
@@ -37,8 +37,6 @@ class Compare
alias_method :commit, :head_commit
def base_commit
- return start_commit if @straight
-
return @base_commit if defined?(@base_commit)
@base_commit = if start_commit && head_commit
@@ -48,6 +46,18 @@ class Compare
end
end
+ def start_commit_sha
+ start_commit.try(:sha)
+ end
+
+ def base_commit_sha
+ base_commit.try(:sha)
+ end
+
+ def head_commit_sha
+ commit.try(:sha)
+ end
+
def raw_diffs(*args)
@compare.diffs(*args)
end
@@ -61,9 +71,9 @@ class Compare
def diff_refs
Gitlab::Diff::DiffRefs.new(
- base_sha: base_commit.try(:sha),
- start_sha: start_commit.try(:sha),
- head_sha: commit.try(:sha)
+ base_sha: @straight ? start_commit_sha : base_commit_sha,
+ start_sha: start_commit_sha,
+ head_sha: head_commit_sha
)
end
end