summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-08-23 17:14:21 +0200
committerJacob Vosmaer <jacob@gitlab.com>2017-08-31 15:35:59 +0200
commit8ad690b0d4f9db528c40e7f523e6f8219c944d48 (patch)
treecafe45b09c7f18a196b69897a77387b19cfaaff1 /app/services
parent3e092caa91853afeab3bb01be10869e45c39de5d (diff)
downloadgitlab-ce-8ad690b0d4f9db528c40e7f523e6f8219c944d48.tar.gz
Prepare GitOperationService for move to Gitlab::Git
Diffstat (limited to 'app/services')
-rw-r--r--app/services/compare_service.rb22
-rw-r--r--app/services/git_operation_service.rb27
2 files changed, 18 insertions, 31 deletions
diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb
index a5ae4927412..53f16a236d2 100644
--- a/app/services/compare_service.rb
+++ b/app/services/compare_service.rb
@@ -11,26 +11,8 @@ class CompareService
end
def execute(target_project, target_branch, straight: false)
- # If compare with other project we need to fetch ref first
- target_project.repository.with_repo_branch_commit(
- start_project.repository,
- start_branch_name) do |commit|
- break unless commit
+ raw_compare = target_project.repository.compare_source_branch(target_branch, start_project.repository, start_branch_name, straight: straight)
- compare(commit.sha, target_project, target_branch, straight: straight)
- end
- end
-
- private
-
- def compare(source_sha, target_project, target_branch, straight:)
- raw_compare = Gitlab::Git::Compare.new(
- target_project.repository.raw_repository,
- target_branch,
- source_sha,
- straight: straight
- )
-
- Compare.new(raw_compare, target_project, straight: straight)
+ Compare.new(raw_compare, target_project, straight: straight) if raw_compare
end
end
diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb
index 6b7a56e6922..b484e9f6f2b 100644
--- a/app/services/git_operation_service.rb
+++ b/app/services/git_operation_service.rb
@@ -5,6 +5,11 @@ class GitOperationService
committer = Gitlab::Git::Committer.from_user(committer) if committer.is_a?(User)
@committer = committer
+ # Refactoring aid
+ unless new_repository.is_a?(Gitlab::Git::Repository)
+ raise "expected a Gitlab::Git::Repository, got #{new_repository}"
+ end
+
@repository = new_repository
end
@@ -55,10 +60,14 @@ class GitOperationService
def with_branch(
branch_name,
start_branch_name: nil,
- start_project: repository.project,
+ start_repository: repository,
&block)
- start_repository = start_project.repository
+ # Refactoring aid
+ unless start_repository.is_a?(Gitlab::Git::Repository)
+ raise "expected a Gitlab::Git::Repository, got #{start_repository}"
+ end
+
start_branch_name = nil if start_repository.empty_repo?
if start_branch_name && !start_repository.branch_exists?(start_branch_name)
@@ -75,6 +84,7 @@ class GitOperationService
private
+ # Returns [newrev, should_run_after_create, should_run_after_create_branch]
def update_branch_with_hooks(branch_name)
update_autocrlf_option
@@ -93,12 +103,7 @@ class GitOperationService
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
update_ref_in_hooks(ref, newrev, oldrev)
- # If repo was empty expire cache
- repository.after_create if was_empty
- repository.after_create_branch if
- was_empty || Gitlab::Git.blank_ref?(oldrev)
-
- newrev
+ [newrev, was_empty, was_empty || Gitlab::Git.blank_ref?(oldrev)]
end
def find_oldrev_from_branch(newrev, branch)
@@ -140,7 +145,7 @@ class GitOperationService
command = %W[#{Gitlab.config.git.bin_path} update-ref --stdin -z]
_, status = Gitlab::Popen.popen(
command,
- repository.path_to_repo) do |stdin|
+ repository.path) do |stdin|
stdin.write("update #{ref}\x00#{newrev}\x00#{oldrev}\x00")
end
@@ -152,8 +157,8 @@ class GitOperationService
end
def update_autocrlf_option
- if repository.raw_repository.autocrlf != :input
- repository.raw_repository.autocrlf = :input
+ if repository.autocrlf != :input
+ repository.autocrlf = :input
end
end
end