Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b48c4b26
Commit
b48c4b26
authored
Oct 12, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor straight compare diff code
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
7421c08a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
12 deletions
+22
-12
app/models/compare.rb
app/models/compare.rb
+16
-6
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+2
-2
app/services/compare_service.rb
app/services/compare_service.rb
+2
-2
spec/services/compare_service_spec.rb
spec/services/compare_service_spec.rb
+2
-2
No files found.
app/models/compare.rb
View file @
b48c4b26
...
@@ -11,7 +11,7 @@ class Compare
...
@@ -11,7 +11,7 @@ class Compare
end
end
end
end
def
initialize
(
compare
,
project
,
straight
=
false
)
def
initialize
(
compare
,
project
,
straight
:
false
)
@compare
=
compare
@compare
=
compare
@project
=
project
@project
=
project
@straight
=
straight
@straight
=
straight
...
@@ -37,8 +37,6 @@ class Compare
...
@@ -37,8 +37,6 @@ class Compare
alias_method
:commit
,
:head_commit
alias_method
:commit
,
:head_commit
def
base_commit
def
base_commit
return
start_commit
if
@straight
return
@base_commit
if
defined?
(
@base_commit
)
return
@base_commit
if
defined?
(
@base_commit
)
@base_commit
=
if
start_commit
&&
head_commit
@base_commit
=
if
start_commit
&&
head_commit
...
@@ -48,6 +46,18 @@ class Compare
...
@@ -48,6 +46,18 @@ class Compare
end
end
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
)
def
raw_diffs
(
*
args
)
@compare
.
diffs
(
*
args
)
@compare
.
diffs
(
*
args
)
end
end
...
@@ -61,9 +71,9 @@ class Compare
...
@@ -61,9 +71,9 @@ class Compare
def
diff_refs
def
diff_refs
Gitlab
::
Diff
::
DiffRefs
.
new
(
Gitlab
::
Diff
::
DiffRefs
.
new
(
base_sha:
base_commit
.
try
(
:sha
)
,
base_sha:
@straight
?
start_commit_sha
:
base_commit_sha
,
start_sha:
start_commit
.
try
(
:sha
)
,
start_sha:
start_commit
_sha
,
head_sha:
commit
.
try
(
:sha
)
head_sha:
head_commit_sha
)
)
end
end
end
end
app/models/merge_request_diff.rb
View file @
b48c4b26
...
@@ -167,11 +167,11 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -167,11 +167,11 @@ class MergeRequestDiff < ActiveRecord::Base
self
==
merge_request
.
merge_request_diff
self
==
merge_request
.
merge_request_diff
end
end
def
compare_with
(
sha
,
straight
=
true
)
def
compare_with
(
sha
,
straight
:
true
)
# When compare merge request versions we want diff A..B instead of A...B
# When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user does squash and rebase of the commits between versions.
# so we handle cases when user does squash and rebase of the commits between versions.
# For this reason we set straight to true by default.
# For this reason we set straight to true by default.
CompareService
.
new
.
execute
(
project
,
head_commit_sha
,
project
,
sha
,
straight
)
CompareService
.
new
.
execute
(
project
,
head_commit_sha
,
project
,
sha
,
straight
:
straight
)
end
end
private
private
...
...
app/services/compare_service.rb
View file @
b48c4b26
...
@@ -3,7 +3,7 @@ require 'securerandom'
...
@@ -3,7 +3,7 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs
# and return Gitlab::Git::Compare object that responds to commits and diffs
class
CompareService
class
CompareService
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
,
straight
=
false
)
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
,
straight
:
false
)
source_commit
=
source_project
.
commit
(
source_branch
)
source_commit
=
source_project
.
commit
(
source_branch
)
return
unless
source_commit
return
unless
source_commit
...
@@ -27,6 +27,6 @@ class CompareService
...
@@ -27,6 +27,6 @@ class CompareService
straight
straight
)
)
Compare
.
new
(
raw_compare
,
target_project
,
straight
)
Compare
.
new
(
raw_compare
,
target_project
,
straight
:
straight
)
end
end
end
end
spec/services/compare_service_spec.rb
View file @
b48c4b26
...
@@ -7,13 +7,13 @@ describe CompareService, services: true do
...
@@ -7,13 +7,13 @@ describe CompareService, services: true do
describe
'#execute'
do
describe
'#execute'
do
context
'compare with base, like feature...fix'
do
context
'compare with base, like feature...fix'
do
subject
{
service
.
execute
(
project
,
'feature'
,
project
,
'fix'
,
false
)
}
subject
{
service
.
execute
(
project
,
'feature'
,
project
,
'fix'
,
straight:
false
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
1
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
1
)
}
end
end
context
'straight compare, like feature..fix'
do
context
'straight compare, like feature..fix'
do
subject
{
service
.
execute
(
project
,
'feature'
,
project
,
'fix'
,
true
)
}
subject
{
service
.
execute
(
project
,
'feature'
,
project
,
'fix'
,
straight:
true
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
3
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
3
)
}
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment