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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
64dfe2cb
Commit
64dfe2cb
authored
Jul 05, 2018
by
Jacob Vosmaer (GitLab)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'gitaly-mandatory-20180703-jv' into 'master'"
This reverts merge request !20339
parent
fe695ebd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
8 deletions
+123
-8
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+12
-2
lib/gitlab/git/conflict/resolver.rb
lib/gitlab/git/conflict/resolver.rb
+65
-4
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+17
-2
spec/services/merge_requests/conflicts/list_service_spec.rb
spec/services/merge_requests/conflicts/list_service_spec.rb
+18
-0
spec/services/merge_requests/conflicts/resolve_service_spec.rb
...services/merge_requests/conflicts/resolve_service_spec.rb
+11
-0
No files found.
lib/gitlab/git/commit.rb
View file @
64dfe2cb
...
@@ -63,8 +63,12 @@ module Gitlab
...
@@ -63,8 +63,12 @@ module Gitlab
# This saves us an RPC round trip.
# This saves us an RPC round trip.
return
nil
if
commit_id
.
include?
(
':'
)
return
nil
if
commit_id
.
include?
(
':'
)
commit
=
repo
.
wrapped_gitaly_errors
do
commit
=
repo
.
gitaly_migrate
(
:find_commit
)
do
|
is_enabled
|
if
is_enabled
repo
.
gitaly_commit_client
.
find_commit
(
commit_id
)
repo
.
gitaly_commit_client
.
find_commit
(
commit_id
)
else
rugged_find
(
repo
,
commit_id
)
end
end
end
decorate
(
repo
,
commit
)
if
commit
decorate
(
repo
,
commit
)
if
commit
...
@@ -74,6 +78,12 @@ module Gitlab
...
@@ -74,6 +78,12 @@ module Gitlab
nil
nil
end
end
def
rugged_find
(
repo
,
commit_id
)
obj
=
repo
.
rev_parse_target
(
commit_id
)
obj
.
is_a?
(
Rugged
::
Commit
)
?
obj
:
nil
end
# Get last commit for HEAD
# Get last commit for HEAD
#
#
# Ex.
# Ex.
...
...
lib/gitlab/git/conflict/resolver.rb
View file @
64dfe2cb
...
@@ -12,8 +12,14 @@ module Gitlab
...
@@ -12,8 +12,14 @@ module Gitlab
end
end
def
conflicts
def
conflicts
@conflicts
||=
@target_repository
.
wrapped_gitaly_errors
do
@conflicts
||=
begin
@target_repository
.
gitaly_migrate
(
:conflicts_list_conflict_files
)
do
|
is_enabled
|
if
is_enabled
gitaly_conflicts_client
(
@target_repository
).
list_conflict_files
.
to_a
gitaly_conflicts_client
(
@target_repository
).
list_conflict_files
.
to_a
else
rugged_list_conflict_files
end
end
end
end
rescue
GRPC
::
FailedPrecondition
=>
e
rescue
GRPC
::
FailedPrecondition
=>
e
raise
Gitlab
::
Git
::
Conflict
::
Resolver
::
ConflictSideMissing
.
new
(
e
.
message
)
raise
Gitlab
::
Git
::
Conflict
::
Resolver
::
ConflictSideMissing
.
new
(
e
.
message
)
...
@@ -22,8 +28,12 @@ module Gitlab
...
@@ -22,8 +28,12 @@ module Gitlab
end
end
def
resolve_conflicts
(
source_repository
,
resolution
,
source_branch
:,
target_branch
:)
def
resolve_conflicts
(
source_repository
,
resolution
,
source_branch
:,
target_branch
:)
source_repository
.
wrapped_gitaly_errors
do
source_repository
.
gitaly_migrate
(
:conflicts_resolve_conflicts
)
do
|
is_enabled
|
if
is_enabled
gitaly_conflicts_client
(
source_repository
).
resolve_conflicts
(
@target_repository
,
resolution
,
source_branch
,
target_branch
)
gitaly_conflicts_client
(
source_repository
).
resolve_conflicts
(
@target_repository
,
resolution
,
source_branch
,
target_branch
)
else
rugged_resolve_conflicts
(
source_repository
,
resolution
,
source_branch
,
target_branch
)
end
end
end
end
end
...
@@ -51,6 +61,57 @@ module Gitlab
...
@@ -51,6 +61,57 @@ module Gitlab
def
gitaly_conflicts_client
(
repository
)
def
gitaly_conflicts_client
(
repository
)
repository
.
gitaly_conflicts_client
(
@our_commit_oid
,
@their_commit_oid
)
repository
.
gitaly_conflicts_client
(
@our_commit_oid
,
@their_commit_oid
)
end
end
def
write_resolved_file_to_index
(
repository
,
index
,
file
,
params
)
if
params
[
:sections
]
resolved_lines
=
file
.
resolve_lines
(
params
[
:sections
])
new_file
=
resolved_lines
.
map
{
|
line
|
line
[
:full_line
]
}.
join
(
"
\n
"
)
new_file
<<
"
\n
"
if
file
.
our_blob
.
data
.
end_with?
(
"
\n
"
)
elsif
params
[
:content
]
new_file
=
file
.
resolve_content
(
params
[
:content
])
end
our_path
=
file
.
our_path
oid
=
repository
.
rugged
.
write
(
new_file
,
:blob
)
index
.
add
(
path:
our_path
,
oid:
oid
,
mode:
file
.
our_mode
)
index
.
conflict_remove
(
our_path
)
end
def
rugged_list_conflict_files
target_index
=
@target_repository
.
rugged
.
merge_commits
(
@our_commit_oid
,
@their_commit_oid
)
# We don't need to do `with_repo_branch_commit` here, because the target
# project always fetches source refs when creating merge request diffs.
conflict_files
(
@target_repository
,
target_index
)
end
def
rugged_resolve_conflicts
(
source_repository
,
resolution
,
source_branch
,
target_branch
)
source_repository
.
with_repo_branch_commit
(
@target_repository
,
target_branch
)
do
index
=
source_repository
.
rugged
.
merge_commits
(
@our_commit_oid
,
@their_commit_oid
)
conflicts
=
conflict_files
(
source_repository
,
index
)
resolution
.
files
.
each
do
|
file_params
|
conflict_file
=
conflict_for_path
(
conflicts
,
file_params
[
:old_path
],
file_params
[
:new_path
])
write_resolved_file_to_index
(
source_repository
,
index
,
conflict_file
,
file_params
)
end
unless
index
.
conflicts
.
empty?
missing_files
=
index
.
conflicts
.
map
{
|
file
|
file
[
:ours
][
:path
]
}
raise
ResolutionError
,
"Missing resolutions for the following files:
#{
missing_files
.
join
(
', '
)
}
"
end
commit_params
=
{
message:
resolution
.
commit_message
,
parents:
[
@our_commit_oid
,
@their_commit_oid
]
}
source_repository
.
commit_index
(
resolution
.
user
,
source_branch
,
index
,
commit_params
)
end
end
end
end
end
end
end
end
...
...
lib/gitlab/git/repository.rb
View file @
64dfe2cb
...
@@ -555,8 +555,12 @@ module Gitlab
...
@@ -555,8 +555,12 @@ module Gitlab
# diff options. The +options+ hash can also include :break_rewrites to
# diff options. The +options+ hash can also include :break_rewrites to
# split larger rewrites into delete/add pairs.
# split larger rewrites into delete/add pairs.
def
diff
(
from
,
to
,
options
=
{},
*
paths
)
def
diff
(
from
,
to
,
options
=
{},
*
paths
)
iterator
=
wrapped_gitaly_errors
do
iterator
=
gitaly_migrate
(
:diff_between
)
do
|
is_enabled
|
if
is_enabled
gitaly_commit_client
.
diff
(
from
,
to
,
options
.
merge
(
paths:
paths
))
gitaly_commit_client
.
diff
(
from
,
to
,
options
.
merge
(
paths:
paths
))
else
diff_patches
(
from
,
to
,
options
,
*
paths
)
end
end
end
Gitlab
::
Git
::
DiffCollection
.
new
(
iterator
,
options
)
Gitlab
::
Git
::
DiffCollection
.
new
(
iterator
,
options
)
...
@@ -1587,6 +1591,17 @@ module Gitlab
...
@@ -1587,6 +1591,17 @@ module Gitlab
tmp_entry
tmp_entry
end
end
# Return the Rugged patches for the diff between +from+ and +to+.
def
diff_patches
(
from
,
to
,
options
=
{},
*
paths
)
options
||=
{}
break_rewrites
=
options
[
:break_rewrites
]
actual_options
=
Gitlab
::
Git
::
Diff
.
filter_diff_options
(
options
.
merge
(
paths:
paths
))
diff
=
rugged
.
diff
(
from
,
to
,
actual_options
)
diff
.
find_similar!
(
break_rewrites:
break_rewrites
)
diff
.
each_patch
end
def
sort_branches
(
branches
,
sort_by
)
def
sort_branches
(
branches
,
sort_by
)
case
sort_by
case
sort_by
when
'name'
when
'name'
...
...
spec/services/merge_requests/conflicts/list_service_spec.rb
View file @
64dfe2cb
...
@@ -84,5 +84,23 @@ describe MergeRequests::Conflicts::ListService do
...
@@ -84,5 +84,23 @@ describe MergeRequests::Conflicts::ListService do
expect
(
service
.
can_be_resolved_in_ui?
).
to
be_falsey
expect
(
service
.
can_be_resolved_in_ui?
).
to
be_falsey
end
end
context
'with gitaly disabled'
,
:skip_gitaly_mock
do
it
'returns a falsey value when the MR has a missing ref after a force push'
do
merge_request
=
create_merge_request
(
'conflict-resolvable'
)
service
=
conflicts_service
(
merge_request
)
allow_any_instance_of
(
Rugged
::
Repository
).
to
receive
(
:merge_commits
).
and_raise
(
Rugged
::
OdbError
)
expect
(
service
.
can_be_resolved_in_ui?
).
to
be_falsey
end
it
'returns a falsey value when the MR has a missing revision after a force push'
do
merge_request
=
create_merge_request
(
'conflict-resolvable'
)
service
=
conflicts_service
(
merge_request
)
allow
(
merge_request
).
to
receive_message_chain
(
:target_branch_head
,
:raw
,
:id
).
and_return
(
Gitlab
::
Git
::
BLANK_SHA
)
expect
(
service
.
can_be_resolved_in_ui?
).
to
be_falsey
end
end
end
end
end
end
spec/services/merge_requests/conflicts/resolve_service_spec.rb
View file @
64dfe2cb
...
@@ -123,6 +123,17 @@ describe MergeRequests::Conflicts::ResolveService do
...
@@ -123,6 +123,17 @@ describe MergeRequests::Conflicts::ResolveService do
expect
(
merge_request_from_fork
.
source_branch_head
.
parents
.
map
(
&
:id
))
expect
(
merge_request_from_fork
.
source_branch_head
.
parents
.
map
(
&
:id
))
.
to
eq
([
'404fa3fc7c2c9b5dacff102f353bdf55b1be2813'
,
target_head
])
.
to
eq
([
'404fa3fc7c2c9b5dacff102f353bdf55b1be2813'
,
target_head
])
end
end
context
'when gitaly is disabled'
,
:skip_gitaly_mock
do
it
'gets conflicts from the source project'
do
# REFACTOR NOTE: We used to test that `project.repository.rugged` wasn't
# used in this case, but since the refactor, for simplification,
# we always use that repository for read only operations.
expect
(
forked_project
.
repository
.
rugged
).
to
receive
(
:merge_commits
).
and_call_original
subject
end
end
end
end
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