diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-02-01 17:20:37 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2018-02-01 17:20:37 +0300 |
commit | 4a8535e769e6dfe9b86dcf86ce9a2ca1124fa5dc (patch) | |
tree | e169d857e4bf4b08c58810fdc2c6cf9d552a1754 | |
parent | 79571919c7fa920eaa76201ceb86ca9ec5008b30 (diff) | |
parent | 6b2005d63c31b492db9153608bd3d01dd574d441 (diff) |
Merge branch 'vendor-gitlab-git-20180201.1013' into 'master'
Vendor gitlab_git at 498d32363aa61d679ff749b
See merge request gitlab-org/gitaly!579
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | internal/service/commit/find_commits_test.go | 16 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/repository_service.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/REVISION | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb | 4 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/operation_service.rb | 5 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/path_helper.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/ref.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb | 190 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/tree.rb | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb | 14 |
14 files changed, 163 insertions, 84 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 848a6cabc..3c2427864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ UNRELEASED +- Vendor gitlab_git at 498d32363aa61d679ff749b + https://gitlab.com/gitlab-org/gitaly/merge_requests/579 - Convert inputs to UTF-8 before passing them to Gollum https://gitlab.com/gitlab-org/gitaly/merge_requests/575 - Implement OperationService.UserSquash RPC diff --git a/internal/service/commit/find_commits_test.go b/internal/service/commit/find_commits_test.go index 64a907710..1eb970c88 100644 --- a/internal/service/commit/find_commits_test.go +++ b/internal/service/commit/find_commits_test.go @@ -162,22 +162,6 @@ func TestSuccessfulFindCommitsRequest(t *testing.T) { Repository: testRepo, Revision: []byte("0031876facac3f2b2702a0e53a26e89939a42209"), }, - ids: []string{ - "0031876facac3f2b2702a0e53a26e89939a42209", - "bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb", - "48ca272b947f49eee601639d743784a176574a09", - "9d526f87b82e2b2fd231ca44c95508e5e85624ca", - "335bc94d5b7369b10251e612158da2e4a4aaa2a5", - "1039376155a0d507eba0ea95c29f8f5b983ea34b", - "54188278422b1fa877c2e71c4e37fc6640a58ad1", - "8b9270332688d58e25206601900ee5618fab2390", - "f9220df47bce1530e90c189064d301bfc8ceb5ab", - "40d408f89c1fd26b7d02e891568f880afe06a9f8", - "df914c609a1e16d7d68e4a61777ff5d6f6b6fde3", - "6762605237fc246ae146ac64ecb467f71d609120", - "79b06233d3dc769921576771a4e8bee4b439595d", - "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", - }, }, { desc: "revision, default commit limit, bypassing rugged walk", diff --git a/ruby/lib/gitaly_server/repository_service.rb b/ruby/lib/gitaly_server/repository_service.rb index 0c3bf5b30..4e8915ab8 100644 --- a/ruby/lib/gitaly_server/repository_service.rb +++ b/ruby/lib/gitaly_server/repository_service.rb @@ -44,7 +44,7 @@ module GitalyServer bridge_exceptions do begin repo = Gitlab::Git::Repository.from_gitaly(request.repository, call) - base = repo.merge_base_commit(*request.revisions) + base = repo.merge_base(*request.revisions) Gitaly::FindMergeBaseResponse.new(base: base.to_s) rescue Rugged::ReferenceError diff --git a/ruby/vendor/gitlab_git/REVISION b/ruby/vendor/gitlab_git/REVISION index 3e31aea7b..edefce111 100644 --- a/ruby/vendor/gitlab_git/REVISION +++ b/ruby/vendor/gitlab_git/REVISION @@ -1 +1 @@ -a03ea19332736c36ecb92c2ccc0ca3364ae77c2e +498d32363aa61d679ff749be727a6591257afb6d diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git.rb b/ruby/vendor/gitlab_git/lib/gitlab/git.rb index 71647099f..c77db0f68 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git.rb @@ -11,7 +11,7 @@ module Gitlab include Gitlab::EncodingHelper def ref_name(ref) - encode!(ref).sub(/\Arefs\/(tags|heads|remotes)\//, '') + encode!(ref).sub(%r{\Arefs/(tags|heads|remotes)/}, '') end def branch_name(ref) diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb index 131201202..4828301db 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb @@ -107,7 +107,7 @@ module Gitlab def find_entry_by_path(repository, root_id, path) root_tree = repository.lookup(root_id) # Strip leading slashes - path[/^\/*/] = '' + path[%r{^/*}] = '' path_arr = path.split('/') entry = root_tree.find do |entry| @@ -140,7 +140,7 @@ module Gitlab def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) return unless path - path = path.sub(/\A\/*/, '') + path = path.sub(%r{\A/*}, '') path = '/' if path.empty? name = File.basename(path) diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb index ca94b4baa..a203587ae 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb @@ -44,7 +44,7 @@ module Gitlab # branch1...branch2) From the git documentation: # "git diff A...B" is equivalent to "git diff # $(git-merge-base A B) B" - repo.merge_base_commit(head, base) + repo.merge_base(head, base) end options ||= {} diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/operation_service.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/operation_service.rb index 3fb0e2eed..280def182 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/operation_service.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/operation_service.rb @@ -131,7 +131,10 @@ module Gitlab oldrev = branch.target - if oldrev == repository.merge_base(newrev, branch.target) + merge_base = repository.merge_base(newrev, branch.target) + raise Gitlab::Git::Repository::InvalidRef unless merge_base + + if oldrev == merge_base oldrev else raise Gitlab::Git::CommitError.new('Branch diverged') diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/path_helper.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/path_helper.rb index 42c80aabd..155cf52f0 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/path_helper.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/path_helper.rb @@ -6,7 +6,7 @@ module Gitlab class << self def normalize_path(filename) # Strip all leading slashes so that //foo -> foo - filename[/^\/*/] = '' + filename[%r{^/*}] = '' # Expand relative paths (e.g. foo/../bar) filename = Pathname.new(filename) diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/ref.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/ref.rb index a3ba9475a..fa71a4e7e 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/ref.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/ref.rb @@ -23,7 +23,7 @@ module Gitlab # Ex. # Ref.extract_branch_name('refs/heads/master') #=> 'master' def self.extract_branch_name(str) - str.gsub(/\Arefs\/heads\//, '') + str.gsub(%r{\Arefs/heads/}, '') end # Gitaly: this method will probably be migrated indirectly via its call sites. diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb index 3a7930154..68b54d288 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb @@ -462,7 +462,6 @@ module Gitlab path: nil, follow: false, skip_merges: false, - disable_walk: false, after: nil, before: nil } @@ -494,11 +493,7 @@ module Gitlab return [] end - if log_using_shell?(options) - log_by_shell(sha, options) - else - log_by_walk(sha, options) - end + log_by_shell(sha, options) end def count_commits(options) @@ -551,29 +546,34 @@ module Gitlab end # Returns the SHA of the most recent common ancestor of +from+ and +to+ - def merge_base_commit(from, to) + def merge_base(from, to) gitaly_migrate(:merge_base) do |is_enabled| if is_enabled gitaly_repository_client.find_merge_base(from, to) else - rugged.merge_base(from, to) + rugged_merge_base(from, to) end end end - alias_method :merge_base, :merge_base_commit # Gitaly note: JV: check gitlab-ee before removing this method. def rugged_is_ancestor?(ancestor_id, descendant_id) return false if ancestor_id.nil? || descendant_id.nil? - merge_base_commit(ancestor_id, descendant_id) == ancestor_id + rugged_merge_base(ancestor_id, descendant_id) == ancestor_id rescue Rugged::OdbError false end # Returns true is +from+ is direct ancestor to +to+, otherwise false def ancestor?(from, to) - gitaly_commit_client.ancestor?(from, to) + Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled| + if is_enabled + gitaly_commit_client.ancestor?(from, to) + else + rugged_is_ancestor?(from, to) + end + end end def merged_branch_names(branch_names = []) @@ -680,11 +680,7 @@ module Gitlab if is_enabled gitaly_commit_client.commit_count(ref) else - walker = Rugged::Walker.new(rugged) - walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) - oid = rugged.rev_parse_oid(ref) - walker.push(oid) - walker.count + rugged_commit_count(ref) end end end @@ -887,16 +883,12 @@ module Gitlab end def delete_refs(*ref_names) - instructions = ref_names.map do |ref| - "delete #{ref}\x00\x00" - end - - message, status = run_git(%w[update-ref --stdin -z]) do |stdin| - stdin.write(instructions.join) - end - - unless status.zero? - raise GitError.new("Could not delete refs #{ref_names}: #{message}") + gitaly_migrate(:delete_refs) do |is_enabled| + if is_enabled + gitaly_delete_refs(*ref_names) + else + git_delete_refs(*ref_names) + end end end @@ -1105,10 +1097,14 @@ module Gitlab end def write_ref(ref_path, ref, old_ref: nil, shell: true) - if shell - shell_write_ref(ref_path, ref, old_ref) - else - rugged_write_ref(ref_path, ref) + ref_path = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{ref_path}" unless ref_path.start_with?("refs/") || ref_path == "HEAD" + + gitaly_migrate(:write_ref) do |is_enabled| + if is_enabled + gitaly_repository_client.write_ref(ref_path, ref, old_ref, shell) + else + local_write_ref(ref_path, ref, old_ref: old_ref, shell: shell) + end end end @@ -1131,13 +1127,6 @@ module Gitlab end # Refactoring aid; allows us to copy code from app/models/repository.rb - def run_git_with_timeout(args, timeout, env: {}) - circuit_breaker.perform do - popen_with_timeout([Gitlab.config.git.bin_path, *args], timeout, path, env) - end - end - - # Refactoring aid; allows us to copy code from app/models/repository.rb def commit(ref = 'HEAD') Gitlab::Git::Commit.find(self, ref) end @@ -1392,8 +1381,18 @@ module Gitlab run_git(args).first.scrub.split(/^--$/) end + def can_be_merged?(source_sha, target_branch) + gitaly_migrate(:can_be_merged) do |is_enabled| + if is_enabled + gitaly_can_be_merged?(source_sha, find_branch(target_branch, true).target) + else + rugged_can_be_merged?(source_sha, target_branch) + end + end + end + def search_files_by_name(query, ref) - safe_query = Regexp.escape(query.sub(/^\/*/, "")) + safe_query = Regexp.escape(query.sub(%r{^/*}, "")) return [] if empty? || safe_query.blank? @@ -1417,8 +1416,36 @@ module Gitlab output end + def can_be_merged?(source_sha, target_branch) + gitaly_migrate(:can_be_merged) do |is_enabled| + if is_enabled + gitaly_can_be_merged?(source_sha, find_branch(target_branch).target) + else + rugged_can_be_merged?(source_sha, target_branch) + end + end + end + + def last_commit_id_for_path(sha, path) + gitaly_migrate(:last_commit_for_path) do |is_enabled| + if is_enabled + last_commit_for_path_by_gitaly(sha, path).id + else + last_commit_id_for_path_by_shelling_out(sha, path) + end + end + end + private + def local_write_ref(ref_path, ref, old_ref: nil, shell: true) + if shell + shell_write_ref(ref_path, ref, old_ref) + else + rugged_write_ref(ref_path, ref) + end + end + def shell_write_ref(ref_path, ref, old_ref) raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ') raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00") @@ -1460,6 +1487,12 @@ module Gitlab output end + def run_git_with_timeout(args, timeout, env: {}) + circuit_breaker.perform do + popen_with_timeout([Gitlab.config.git.bin_path, *args], timeout, path, env) + end + end + def fresh_worktree?(path) File.exist?(path) && !clean_stuck_worktree(path) end @@ -1607,24 +1640,6 @@ module Gitlab end end - def log_using_shell?(options) - options[:path].present? || - options[:disable_walk] || - options[:skip_merges] || - options[:after] || - options[:before] - end - - def log_by_walk(sha, options) - walk_options = { - show: sha, - sort: Rugged::SORT_NONE, - limit: options[:limit], - offset: options[:offset] - } - Rugged::Walker.walk(rugged, walk_options).to_a - end - # Gitaly note: JV: although #log_by_shell shells out to Git I think the # complexity is such that we should migrate it as Ruby before trying to # do it in Go. @@ -1987,7 +2002,7 @@ module Gitlab target_commit = Gitlab::Git::Commit.find(self, rugged_ref.target) Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target, target_commit) rescue Rugged::ReferenceError => e - raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/ + raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ %r{'refs/heads/#{ref}'} raise InvalidRef.new("Invalid reference #{start_point}") end @@ -2160,7 +2175,7 @@ module Gitlab source_sha end - rescue Rugged::ReferenceError + rescue Rugged::ReferenceError, InvalidRef raise ArgumentError, 'Invalid merge source' end @@ -2172,6 +2187,24 @@ module Gitlab remote_update(remote_name, url: url) end + def git_delete_refs(*ref_names) + instructions = ref_names.map do |ref| + "delete #{ref}\x00\x00" + end + + message, status = run_git(%w[update-ref --stdin -z]) do |stdin| + stdin.write(instructions.join) + end + + unless status.zero? + raise GitError.new("Could not delete refs #{ref_names}: #{message}") + end + end + + def gitaly_delete_refs(*ref_names) + gitaly_ref_client.delete_refs(refs: ref_names) + end + def rugged_remove_remote(remote_name) # When a remote is deleted all its remote refs are deleted too, but in # the case of mirrors we map its refs (that would usualy go under @@ -2234,6 +2267,14 @@ module Gitlab run_git(['fetch', remote_name], env: env).last.zero? end + def gitaly_can_be_merged?(their_commit, our_commit) + !gitaly_conflicts_client(our_commit, their_commit).conflicts? + end + + def rugged_can_be_merged?(their_commit, our_commit) + !rugged.merge_commits(our_commit, their_commit).conflicts? + end + def gitlab_projects_error raise CommandError, @gitlab_projects.output end @@ -2257,6 +2298,39 @@ module Gitlab .commits_by_message(query, revision: ref, path: path, limit: limit, offset: offset) .map { |c| commit(c) } end + + def gitaly_can_be_merged?(their_commit, our_commit) + !gitaly_conflicts_client(our_commit, their_commit).conflicts? + end + + def rugged_can_be_merged?(their_commit, our_commit) + !rugged.merge_commits(our_commit, their_commit).conflicts? + end + + def last_commit_for_path_by_gitaly(sha, path) + gitaly_commit_client.last_commit_for_path(sha, path) + end + + def last_commit_id_for_path_by_shelling_out(sha, path) + args = %W(rev-list --max-count=1 #{sha} -- #{path}) + run_git_with_timeout(args, Gitlab::Git::Popen::FAST_GIT_PROCESS_TIMEOUT).first.strip + end + + def rugged_merge_base(from, to) + rugged.merge_base(from, to) + rescue Rugged::ReferenceError + nil + end + + def rugged_commit_count(ref) + walker = Rugged::Walker.new(rugged) + walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) + oid = rugged.rev_parse_oid(ref) + walker.push(oid) + walker.count + rescue Rugged::ReferenceError + 0 + end end end end diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb index effb1f0ca..dc424a433 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb @@ -43,7 +43,7 @@ module Gitlab branches = [] rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref| - name = ref.name.sub(/\Arefs\/remotes\/#{remote_name}\//, '') + name = ref.name.sub(%r{\Arefs/remotes/#{remote_name}/}, '') begin target_commit = Gitlab::Git::Commit.find(self, ref.target) diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/tree.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/tree.rb index 5cf336af3..ba6058fd3 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/tree.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/tree.rb @@ -83,6 +83,8 @@ module Gitlab commit_id: sha ) end + rescue Rugged::ReferenceError + [] end end diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb index d4a53d32c..ccdb89753 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb @@ -117,6 +117,20 @@ module Gitlab page.url_path end + def page_formatted_data(title:, dir: nil, version: nil) + version = version&.id + + @repository.gitaly_migrate(:wiki_page_formatted_data) do |is_enabled| + if is_enabled + gitaly_wiki_client.get_formatted_data(title: title, dir: dir, version: version) + else + # We don't use #page because if wiki_find_page feature is enabled, we would + # get a page without formatted_data. + gollum_find_page(title: title, dir: dir, version: version)&.formatted_data + end + end + end + private # options: |