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
iv
gitlab-ce
Commits
26f5d604
Commit
26f5d604
authored
Jul 15, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor compare and fetch logic
parent
cb6f34e3
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
51 deletions
+36
-51
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+2
-7
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-2
app/models/merge_request.rb
app/models/merge_request.rb
+8
-0
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+10
-12
app/models/repository.rb
app/models/repository.rb
+2
-0
app/services/compare_service.rb
app/services/compare_service.rb
+13
-20
app/services/merge_requests/build_service.rb
app/services/merge_requests/build_service.rb
+0
-1
app/services/merge_requests/create_service.rb
app/services/merge_requests/create_service.rb
+0
-9
No files found.
app/controllers/projects/compare_controller.rb
View file @
26f5d604
...
@@ -13,13 +13,8 @@ class Projects::CompareController < Projects::ApplicationController
...
@@ -13,13 +13,8 @@ class Projects::CompareController < Projects::ApplicationController
base_ref
=
Addressable
::
URI
.
unescape
(
params
[
:from
])
base_ref
=
Addressable
::
URI
.
unescape
(
params
[
:from
])
@ref
=
head_ref
=
Addressable
::
URI
.
unescape
(
params
[
:to
])
@ref
=
head_ref
=
Addressable
::
URI
.
unescape
(
params
[
:to
])
compare_result
=
CompareService
.
new
.
execute
(
compare_result
=
CompareService
.
new
.
current_user
,
execute
(
@project
,
head_ref
,
@project
,
base_ref
)
@project
,
head_ref
,
@project
,
base_ref
)
@commits
=
compare_result
.
commits
@commits
=
compare_result
.
commits
@diffs
=
compare_result
.
diffs
@diffs
=
compare_result
.
diffs
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
26f5d604
...
@@ -149,8 +149,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -149,8 +149,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return
access_denied!
unless
@merge_request
.
can_be_merged_by?
(
current_user
)
return
access_denied!
unless
@merge_request
.
can_be_merged_by?
(
current_user
)
if
@merge_request
.
automergeable?
if
@merge_request
.
automergeable?
#AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params)
AutoMergeWorker
.
perform_async
(
@merge_request
.
id
,
current_user
.
id
,
params
)
@merge_request
.
automerge!
(
current_user
,
params
[
:commit_message
])
@status
=
true
@status
=
true
else
else
@status
=
false
@status
=
false
...
...
app/models/merge_request.rb
View file @
26f5d604
...
@@ -437,4 +437,12 @@ class MergeRequest < ActiveRecord::Base
...
@@ -437,4 +437,12 @@ class MergeRequest < ActiveRecord::Base
def
source_sha
def
source_sha
commits
.
first
.
sha
commits
.
first
.
sha
end
end
def
fetch_ref
target_project
.
repository
.
fetch_ref
(
source_project
.
repository
.
path_to_repo
,
"refs/heads/
#{
source_branch
}
"
,
"refs/merge-requests/
#{
id
}
/head"
)
end
end
end
app/models/merge_request_diff.rb
View file @
26f5d604
...
@@ -162,20 +162,18 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -162,20 +162,18 @@ class MergeRequestDiff < ActiveRecord::Base
def
compare_result
def
compare_result
@compare_result
||=
@compare_result
||=
begin
begin
source_sha
=
merge_request
.
source_project
.
commit
(
source_branch
).
sha
# Update ref if merge request is from fork
merge_request
.
fetch_ref
if
merge_request
.
for_fork?
merge_request
.
target_project
.
repository
.
fetch_ref
(
# Get latest sha of branch from source project
merge_request
.
source_project
.
repository
.
path_to_repo
,
source_sha
=
merge_request
.
source_project
.
commit
(
source_branch
).
sha
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
"refs/merge-requests/
#{
merge_request
.
id
}
/head"
)
CompareService
.
new
.
execute
(
Gitlab
::
CompareResult
.
new
(
merge_request
.
author
,
Gitlab
::
Git
::
Compare
.
new
(
merge_request
.
target_project
,
merge_request
.
target_project
.
repository
.
raw_repository
,
source_sha
,
merge_request
.
target_project
,
merge_request
.
target_branch
,
merge_request
.
target_branch
,
source_sha
,
)
)
)
end
end
end
end
...
...
app/models/repository.rb
View file @
26f5d604
...
@@ -428,6 +428,8 @@ class Repository
...
@@ -428,6 +428,8 @@ class Repository
if
our_commit
&&
their_commit
if
our_commit
&&
their_commit
!
rugged
.
merge_commits
(
our_commit
,
their_commit
).
conflicts?
!
rugged
.
merge_commits
(
our_commit
,
their_commit
).
conflicts?
else
false
end
end
end
end
...
...
app/services/compare_service.rb
View file @
26f5d604
...
@@ -3,25 +3,19 @@ require 'securerandom'
...
@@ -3,25 +3,19 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# Compare 2 branches for one repo or between repositories
# and return Gitlab::CompareResult object that responds to commits and diffs
# and return Gitlab::CompareResult object that responds to commits and diffs
class
CompareService
class
CompareService
def
execute
(
current_user
,
source_project
,
source_branch
,
target_project
,
target_branch
)
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
)
# Try to compare branches to get commits list and diffs
source_sha
=
source_project
.
commit
(
source_branch
).
sha
if
target_project
==
source_project
Gitlab
::
CompareResult
.
new
(
# If compare with other project we need to fetch ref first
Gitlab
::
Git
::
Compare
.
new
(
unless
target_project
==
source_project
target_project
.
repository
.
raw_repository
,
target_branch
,
source_branch
,
)
)
else
random_string
=
SecureRandom
.
hex
random_string
=
SecureRandom
.
hex
target_project
.
repository
.
fetch_ref
(
target_project
.
repository
.
fetch_ref
(
source_project
.
repository
.
path_to_repo
,
source_project
.
repository
.
path_to_repo
,
"refs/heads/
#{
source_branch
}
"
,
"refs/heads/
#{
source_branch
}
"
,
"refs/tmp/
#{
random_string
}
/head"
"refs/tmp/
#{
random_string
}
/head"
)
)
end
source_sha
=
source_project
.
commit
(
source_branch
).
sha
Gitlab
::
CompareResult
.
new
(
Gitlab
::
CompareResult
.
new
(
Gitlab
::
Git
::
Compare
.
new
(
Gitlab
::
Git
::
Compare
.
new
(
...
@@ -31,5 +25,4 @@ class CompareService
...
@@ -31,5 +25,4 @@ class CompareService
)
)
)
)
end
end
end
end
end
app/services/merge_requests/build_service.rb
View file @
26f5d604
...
@@ -17,7 +17,6 @@ module MergeRequests
...
@@ -17,7 +17,6 @@ module MergeRequests
end
end
compare_result
=
CompareService
.
new
.
execute
(
compare_result
=
CompareService
.
new
.
execute
(
current_user
,
merge_request
.
source_project
,
merge_request
.
source_project
,
merge_request
.
source_branch
,
merge_request
.
source_branch
,
merge_request
.
target_project
,
merge_request
.
target_project
,
...
...
app/services/merge_requests/create_service.rb
View file @
26f5d604
...
@@ -9,15 +9,6 @@ module MergeRequests
...
@@ -9,15 +9,6 @@ module MergeRequests
merge_request
.
author
=
current_user
merge_request
.
author
=
current_user
if
merge_request
.
save
if
merge_request
.
save
# Fetch fork branch into hidden ref of target repository
if
merge_request
.
for_fork?
merge_request
.
target_project
.
repository
.
fetch_ref
(
merge_request
.
source_project
.
repository
.
path_to_repo
,
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
"refs/merge-requests/
#{
merge_request
.
id
}
/head"
)
end
merge_request
.
update_attributes
(
label_ids:
label_params
)
merge_request
.
update_attributes
(
label_ids:
label_params
)
event_service
.
open_mr
(
merge_request
,
current_user
)
event_service
.
open_mr
(
merge_request
,
current_user
)
notification_service
.
new_merge_request
(
merge_request
,
current_user
)
notification_service
.
new_merge_request
(
merge_request
,
current_user
)
...
...
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