Skip to content
Snippets Groups Projects
Unverified Commit 9f10943c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Revert "Merge branch 'drop-satellites'"


This reverts commit 957e849f, reversing
changes made to 6b9dbe9f.

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 84727fba
No related branches found
No related tags found
No related merge requests found
Showing
with 211 additions and 205 deletions
Loading
Loading
@@ -875,4 +875,4 @@ DEPENDENCIES
wikicloth (= 0.8.1)
 
BUNDLED WITH
1.10.4
1.10.5
Loading
Loading
@@ -19,7 +19,7 @@ class @MergeRequestWidget
when 'merged'
location.reload()
else
setTimeout(merge_request_widget.mergeInProgress, 2000)
setTimeout(merge_request_widget.mergeInProgress, 3000)
dataType: 'json'
 
getMergeStatus: ->
Loading
Loading
Loading
Loading
@@ -13,8 +13,13 @@ class Projects::CompareController < Projects::ApplicationController
base_ref = Addressable::URI.unescape(params[:from])
@ref = head_ref = Addressable::URI.unescape(params[:to])
 
compare_result = CompareService.new.
execute(@project, head_ref, @project, base_ref)
compare_result = CompareService.new.execute(
current_user,
@project,
head_ref,
@project,
base_ref
)
 
@commits = compare_result.commits
@diffs = compare_result.diffs
Loading
Loading
require 'gitlab/satellite/satellite'
class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled
before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :merge, :merge_check,
:edit, :update, :show, :diffs, :commits, :automerge, :automerge_check,
:ci_status, :toggle_subscription
]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits]
Loading
Loading
@@ -135,7 +137,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
 
def merge_check
def automerge_check
if @merge_request.unchecked?
@merge_request.check_if_can_be_merged
end
Loading
Loading
@@ -145,11 +147,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render partial: "projects/merge_requests/widget/show.html.haml", layout: false
end
 
def merge
def automerge
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
 
if @merge_request.mergeable?
MergeWorker.perform_async(@merge_request.id, current_user.id, params)
if @merge_request.automergeable?
AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params)
@status = true
else
@status = false
Loading
Loading
Loading
Loading
@@ -41,6 +41,8 @@ class MergeRequest < ActiveRecord::Base
 
delegate :commits, :diffs, :last_commit, :last_commit_short_sha, to: :merge_request_diff, prefix: nil
 
attr_accessor :should_remove_source_branch
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
attr_accessor :allow_broken
Loading
Loading
@@ -55,7 +57,7 @@ class MergeRequest < ActiveRecord::Base
transition [:reopened, :opened] => :closed
end
 
event :mark_as_merged do
event :merge do
transition [:reopened, :opened, :locked] => :merged
end
 
Loading
Loading
@@ -204,7 +206,11 @@ class MergeRequest < ActiveRecord::Base
 
def check_if_can_be_merged
can_be_merged =
project.repository.can_be_merged?(source_sha, target_branch)
if for_fork?
Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
else
project.repository.can_be_merged?(source_branch, target_branch)
end
 
if can_be_merged
mark_as_mergeable
Loading
Loading
@@ -221,6 +227,18 @@ class MergeRequest < ActiveRecord::Base
self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
end
 
def automerge!(current_user, commit_message = nil)
return unless automergeable?
MergeRequests::AutoMergeService.
new(target_project, current_user).
execute(self, commit_message)
end
def remove_source_branch?
self.should_remove_source_branch && !self.source_project.root_ref?(self.source_branch) && !self.for_fork?
end
def open?
opened? || reopened?
end
Loading
Loading
@@ -229,11 +247,11 @@ class MergeRequest < ActiveRecord::Base
title =~ /\A\[?WIP\]?:? /i
end
 
def mergeable?
def automergeable?
open? && !work_in_progress? && can_be_merged?
end
 
def gitlab_merge_status
def automerge_status
if work_in_progress?
"work_in_progress"
else
Loading
Loading
@@ -260,14 +278,14 @@ class MergeRequest < ActiveRecord::Base
#
# see "git diff"
def to_diff(current_user)
target_project.repository.diff_text(target_branch, source_sha)
Gitlab::Satellite::MergeAction.new(current_user, self).diff_in_satellite
end
 
# Returns the commit as a series of email patches.
#
# see "git format-patch"
def to_patch(current_user)
target_project.repository.format_patch(target_branch, source_sha)
Gitlab::Satellite::MergeAction.new(current_user, self).format_patch
end
 
def hook_attrs
Loading
Loading
@@ -418,30 +436,4 @@ class MergeRequest < ActiveRecord::Base
"Open"
end
end
def target_sha
@target_sha ||= target_project.
repository.commit(target_branch).sha
end
def source_sha
commits.first.sha
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
def in_locked_state
begin
lock_mr
yield
ensure
unlock_mr if locked?
end
end
end
Loading
Loading
@@ -16,8 +16,9 @@ require Rails.root.join("app/models/commit")
class MergeRequestDiff < ActiveRecord::Base
include Sortable
 
# Prevent store of diff if commits amount more then 500
COMMITS_SAFE_SIZE = 500
# Prevent store of diff
# if commits amount more then 200
COMMITS_SAFE_SIZE = 200
 
attr_reader :commits, :diffs
 
Loading
Loading
@@ -123,12 +124,12 @@ class MergeRequestDiff < ActiveRecord::Base
if new_diffs.any?
if new_diffs.size > Commit::DIFF_HARD_LIMIT_FILES
self.state = :overflow_diff_files_limit
new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
new_diffs = []
end
 
if new_diffs.sum { |diff| diff.diff.lines.count } > Commit::DIFF_HARD_LIMIT_LINES
self.state = :overflow_diff_lines_limit
new_diffs = new_diffs.first[Commit::DIFF_HARD_LIMIT_LINES]
new_diffs = []
end
end
 
Loading
Loading
@@ -159,21 +160,12 @@ class MergeRequestDiff < ActiveRecord::Base
private
 
def compare_result
@compare_result ||=
begin
# Update ref if merge request is from fork
merge_request.fetch_ref if merge_request.for_fork?
# Get latest sha of branch from source project
source_sha = merge_request.source_project.commit(source_branch).sha
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
merge_request.target_project.repository.raw_repository,
merge_request.target_branch,
source_sha,
)
)
end
@compare_result ||= CompareService.new.execute(
merge_request.author,
merge_request.source_project,
merge_request.source_branch,
merge_request.target_project,
merge_request.target_branch,
)
end
end
Loading
Loading
@@ -118,11 +118,12 @@ class Namespace < ActiveRecord::Base
gitlab_shell.add_namespace(path_was)
 
if gitlab_shell.mv_namespace(path_was, path)
# If repositories moved successfully we need to
# send update instructions to users.
# If repositories moved successfully we need to remove old satellites
# and send update instructions to users.
# However we cannot allow rollback since we moved namespace dir
# So we basically we mute exceptions in next actions
begin
gitlab_shell.rm_satellites(path_was)
send_update_instructions
rescue
# Returning false does not rollback after_* transaction but gives
Loading
Loading
Loading
Loading
@@ -520,6 +520,14 @@ class Project < ActiveRecord::Base
!repository.exists? || repository.empty?
end
 
def ensure_satellite_exists
self.satellite.create unless self.satellite.exists?
end
def satellite
@satellite ||= Gitlab::Satellite::Satellite.new(self)
end
def repo
repository.raw
end
Loading
Loading
@@ -589,11 +597,14 @@ class Project < ActiveRecord::Base
new_path_with_namespace = File.join(namespace_dir, path)
 
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users.
# If repository moved successfully we need to remove old satellite
# and send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki")
gitlab_shell.rm_satellites(old_path_with_namespace)
ensure_satellite_exists
send_move_instructions
reset_events_cache
rescue
Loading
Loading
@@ -691,6 +702,7 @@ class Project < ActiveRecord::Base
def create_repository
if forked?
if gitlab_shell.fork_repository(forked_from_project.path_with_namespace, self.namespace.path)
ensure_satellite_exists
true
else
errors.add(:base, 'Failed to fork repository via gitlab-shell')
Loading
Loading
Loading
Loading
@@ -74,8 +74,6 @@ class GitlabCiService < CiService
else
:error
end
rescue Errno::ECONNREFUSED
:error
end
 
def fork_registration(new_project, private_token)
Loading
Loading
@@ -105,8 +103,6 @@ class GitlabCiService < CiService
if response.code == 200 and response["coverage"]
response["coverage"]
end
rescue Errno::ECONNREFUSED
nil
end
 
def build_page(sha, ref)
Loading
Loading
Loading
Loading
@@ -411,36 +411,15 @@ class Repository
}
end
 
def can_be_merged?(source_sha, target_branch)
def can_be_merged?(source_branch, target_branch)
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
their_commit = rugged.branches[source_branch].target
 
if our_commit && their_commit
!rugged.merge_commits(our_commit, their_commit).conflicts?
else
false
end
end
 
def merge(source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
raise "Invalid merge target" if our_commit.nil?
raise "Invalid merge source" if their_commit.nil?
merge_index = rugged.merge_commits(our_commit, their_commit)
return false if merge_index.conflicts?
actual_options = options.merge(
parents: [our_commit, their_commit],
tree: merge_index.write_tree(rugged),
update_ref: "refs/heads/#{target_branch}"
)
Rugged::Commit.create(rugged, actual_options)
end
def search_files(query, ref)
offset = 2
args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref})
Loading
Loading
@@ -474,11 +453,6 @@ class Repository
)
end
 
def fetch_ref(source_path, source_ref, target_ref)
args = %W(git fetch #{source_path} #{source_ref}:#{target_ref})
Gitlab::Popen.popen(args, path_to_repo)
end
private
 
def cache
Loading
Loading
Loading
Loading
@@ -31,10 +31,6 @@ class BaseService
SystemHooksService.new
end
 
def repository
project.repository
end
# Add an error to the specified model for restricted visibility levels
def deny_visibility_level(model, denied_visibility_level = nil)
denied_visibility_level ||= model.visibility_level
Loading
Loading
require 'securerandom'
# Compare 2 branches for one repo or between repositories
# and return Gitlab::CompareResult object that responds to commits and diffs
class CompareService
def execute(source_project, source_branch, target_project, target_branch)
source_sha = source_project.commit(source_branch).sha
# If compare with other project we need to fetch ref first
unless target_project == source_project
random_string = SecureRandom.hex
target_project.repository.fetch_ref(
source_project.repository.path_to_repo,
"refs/heads/#{source_branch}",
"refs/tmp/#{random_string}/head"
def execute(current_user, source_project, source_branch, target_project, target_branch)
# Try to compare branches to get commits list and diffs
#
# Note: Use satellite only when need to compare between two repos
# because satellites are slower than operations on bare repo
if target_project == source_project
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
target_project.repository.raw_repository,
target_branch,
source_branch,
)
)
end
Gitlab::CompareResult.new(
Gitlab::Git::Compare.new(
target_project.repository.raw_repository,
else
Gitlab::Satellite::CompareAction.new(
current_user,
target_project,
target_branch,
source_sha,
)
)
source_project,
source_branch
).result
end
end
end
Loading
Loading
@@ -33,8 +33,15 @@ module Files
 
private
 
def repository
project.repository
end
def after_commit(sha, branch)
PostCommitService.new(project, current_user).execute(sha, branch)
commit = repository.commit(sha)
full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}"
old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA
GitPushService.new.execute(project, current_user, old_sha, sha, full_ref)
end
 
def current_branch
Loading
Loading
Loading
Loading
@@ -10,14 +10,16 @@ class GitPushService
#
# Next, this method:
# 1. Creates the push event
# 2. Updates merge requests
# 3. Recognizes cross-references from commit messages
# 4. Executes the project's web hooks
# 5. Executes the project's services
# 2. Ensures that the project satellite exists
# 3. Updates merge requests
# 4. Recognizes cross-references from commit messages
# 5. Executes the project's web hooks
# 6. Executes the project's services
#
def execute(project, user, oldrev, newrev, ref)
@project, @user = project, user
 
project.ensure_satellite_exists
project.repository.expire_cache
 
if push_remove_branch?(ref, newrev)
Loading
Loading
module MergeRequests
# AutoMergeService class
#
# Do git merge in satellite and in case of success
# mark merge request as merged and execute all hooks and notifications
# Called when you do merge via GitLab UI
class AutoMergeService < BaseMergeService
attr_reader :merge_request, :commit_message
def execute(merge_request, commit_message)
@commit_message = commit_message
@merge_request = merge_request
merge_request.lock_mr
if merge!
merge_request.merge
create_merge_event(merge_request, current_user)
create_note(merge_request)
notification_service.merge_mr(merge_request, current_user)
execute_hooks(merge_request, 'merge')
true
else
merge_request.unlock_mr
false
end
rescue
merge_request.unlock_mr if merge_request.locked?
merge_request.mark_as_unmergeable
false
end
def merge!
if merge_request.for_fork?
Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message)
else
# Merge local branches using rugged instead of satellites
if sha = commit
after_commit(sha, merge_request.target_branch)
if merge_request.remove_source_branch?
DeleteBranchService.new(merge_request.source_project, current_user).execute(merge_request.source_branch)
end
true
else
false
end
end
end
def commit
committer = repository.user_to_comitter(current_user)
options = {
message: commit_message,
author: committer,
committer: committer
}
repository.merge(merge_request.source_branch, merge_request.target_branch, options)
end
def after_commit(sha, branch)
commit = repository.commit(sha)
full_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch}"
old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA
GitPushService.new.execute(project, current_user, old_sha, sha, full_ref)
end
def repository
project.repository
end
end
end
module MergeRequests
class BaseMergeService < MergeRequests::BaseService
private
def create_merge_event(merge_request, current_user)
EventCreateService.new.merge_mr(merge_request, current_user)
end
end
end
Loading
Loading
@@ -12,16 +12,12 @@ module MergeRequests
merge_request.target_project ||= (project.forked_from_project || project)
merge_request.target_branch ||= merge_request.target_project.default_branch
 
if merge_request.target_branch.blank? || merge_request.source_branch.blank?
message =
if params[:source_branch] || params[:target_branch]
"You must select source and target branch"
end
return build_failed(merge_request, message)
unless merge_request.target_branch && merge_request.source_branch
return build_failed(merge_request, nil)
end
 
compare_result = CompareService.new.execute(
current_user,
merge_request.source_project,
merge_request.source_branch,
merge_request.target_project,
Loading
Loading
@@ -44,6 +40,7 @@ module MergeRequests
merge_request.compare_diffs = diffs
 
elsif diffs == false
# satellite timeout return false
merge_request.can_be_created = false
merge_request.compare_failed = true
end
Loading
Loading
@@ -62,6 +59,9 @@ module MergeRequests
end
 
merge_request
rescue Gitlab::Satellite::BranchesWithoutParent
return build_failed(merge_request, "Selected branches have no common commit so they cannot be merged.")
end
 
def build_failed(merge_request, message)
Loading
Loading
module MergeRequests
# MergeService class
#
# Do git merge and in case of success
# mark merge request as merged and execute all hooks and notifications
# Executed when you do merge via GitLab UI
#
class MergeService < MergeRequests::BaseService
attr_reader :merge_request, :commit_message
# Mark existing merge request as merged
# and execute all hooks and notifications
# Called when you do merge via command line and push code
# to target branch
class MergeService < BaseMergeService
def execute(merge_request, commit_message)
@commit_message = commit_message
@merge_request = merge_request
merge_request.merge
 
unless @merge_request.mergeable?
return error('Merge request is not mergeable')
end
merge_request.in_locked_state do
if merge_changes
after_merge
success
else
error('Can not merge changes')
end
end
end
private
def merge_changes
if sha = commit
after_commit(sha, merge_request.target_branch)
end
end
def commit
committer = repository.user_to_comitter(current_user)
options = {
message: commit_message,
author: committer,
committer: committer
}
repository.merge(merge_request.source_sha, merge_request.target_branch, options)
end
def after_commit(sha, branch)
PostCommitService.new(project, current_user).execute(sha, branch)
end
create_merge_event(merge_request, current_user)
create_note(merge_request)
notification_service.merge_mr(merge_request, current_user)
execute_hooks(merge_request, 'merge')
 
def after_merge
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
true
rescue
false
end
end
end
module MergeRequests
# PostMergeService class
#
# Mark existing merge request as merged
# and execute all hooks and notifications
#
class PostMergeService < MergeRequests::BaseService
def execute(merge_request)
merge_request.mark_as_merged
create_merge_event(merge_request, current_user)
create_note(merge_request)
notification_service.merge_mr(merge_request, current_user)
execute_hooks(merge_request, 'merge')
end
private
def create_merge_event(merge_request, current_user)
EventCreateService.new.merge_mr(merge_request, current_user)
end
end
end
Loading
Loading
@@ -33,9 +33,9 @@ module MergeRequests
 
 
merge_requests.uniq.select(&:source_project).each do |merge_request|
MergeRequests::PostMergeService.
MergeRequests::MergeService.
new(merge_request.target_project, @current_user).
execute(merge_request)
execute(merge_request, nil)
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment