Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-04-25 13:06:13 +0300
committerJacob Vosmaer (GitLab) <jacob@gitlab.com>2018-04-25 13:06:13 +0300
commitd2123050c4bbbe8f5a068f6e14b34f05eab08735 (patch)
tree5f9ebc95e5b0ddc36f23b05c36b1f0d79c0d3e5e
parent732651ef691a16767a3f3642a17c5f369474c9a9 (diff)
Upgrade ruby vendor
-rw-r--r--CHANGELOG.md2
-rwxr-xr-x_support/vendor-gitlab-git7
-rw-r--r--ruby/lib/gitaly_server/utils.rb2
-rw-r--r--ruby/lib/gitlab/git.rb8
-rw-r--r--ruby/lib/gitlab/git/repository.rb1
-rw-r--r--ruby/vendor/gitlab_git/REVISION2
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git.rb6
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/attributes_parser.rb12
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb2
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/committer_with_hooks.rb47
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb2
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/info_attributes.rb49
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/popen.rb4
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/raw_diff_change.rb60
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb125
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb2
-rwxr-xr-xruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input21
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb60
18 files changed, 307 insertions, 105 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 17f178b47..71b954411 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
UNRELEASED
+- Vendor gitlab_git at 8b41c40674273d6ee
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/684
- Make wiki commit fields backwards compatible
https://gitlab.com/gitlab-org/gitaly/merge_requests/685
- Catch CommitErrors while rebasing
diff --git a/_support/vendor-gitlab-git b/_support/vendor-gitlab-git
index 8baa45921..705de3239 100755
--- a/_support/vendor-gitlab-git
+++ b/_support/vendor-gitlab-git
@@ -1,7 +1,12 @@
#!/usr/bin/env ruby
# These files and directories of gitlab-ce will be vendored
-FILE_LIST = %w[lib/gitlab/git.rb lib/gitlab/git lib/gitlab/encoding_helper.rb lib/gitlab/utils/strong_memoize.rb].freeze
+FILE_LIST = %w[
+ lib/gitlab/git.rb
+ lib/gitlab/git
+ lib/gitlab/encoding_helper.rb
+ lib/gitlab/utils/strong_memoize.rb
+].freeze
REMOTE = 'https://gitlab.com/gitlab-org/gitlab-ce'.freeze
diff --git a/ruby/lib/gitaly_server/utils.rb b/ruby/lib/gitaly_server/utils.rb
index 3b2324338..17d9caeef 100644
--- a/ruby/lib/gitaly_server/utils.rb
+++ b/ruby/lib/gitaly_server/utils.rb
@@ -29,6 +29,8 @@ module GitalyServer
def commit_details_from_gitaly(gitaly_commit_details)
Gitlab::Git::Wiki::CommitDetails.new(
+ gitaly_commit_details.user_id,
+ gitaly_commit_details.user_name,
gitaly_commit_details.name,
gitaly_commit_details.email,
gitaly_commit_details.message
diff --git a/ruby/lib/gitlab/git.rb b/ruby/lib/gitlab/git.rb
index 9ceb46eea..80516553a 100644
--- a/ruby/lib/gitlab/git.rb
+++ b/ruby/lib/gitlab/git.rb
@@ -19,6 +19,10 @@ require_relative 'rails_logger.rb'
require_relative 'gollum.rb'
require_relative 'config.rb'
+def require_dependency(_arg)
+ # no-op
+end
+
vendor_gitlab_git = '../../vendor/gitlab_git/'
# Some later requires are order-sensitive. Manually require whatever we need.
@@ -78,6 +82,10 @@ module Gitlab
def self.gl_id(user)
user.gl_id
end
+
+ def self.gl_id_from_id_value(id)
+ "user-#{id}"
+ end
end
end
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index b4ef62f81..26fb20344 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -26,7 +26,6 @@ module Gitlab
@path = path
@gl_repository = gl_repository
@gitlab_projects = gitlab_projects
- @attributes = Gitlab::Git::InfoAttributes.new(path)
end
def circuit_breaker
diff --git a/ruby/vendor/gitlab_git/REVISION b/ruby/vendor/gitlab_git/REVISION
index 3922a0259..7499b71a1 100644
--- a/ruby/vendor/gitlab_git/REVISION
+++ b/ruby/vendor/gitlab_git/REVISION
@@ -1 +1 @@
-7e3bb679a92156304972e2db1ae49c9b0e4cd188
+8b41c40674273d6ee3d9b0c720e5e51b76998b31
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git.rb b/ruby/vendor/gitlab_git/lib/gitlab/git.rb
index d4e893b88..e85e87a54 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git.rb
@@ -1,5 +1,11 @@
+require_dependency 'gitlab/encoding_helper'
+
module Gitlab
module Git
+ # The ID of empty tree.
+ # See http://stackoverflow.com/a/40884093/1856239 and
+ # https://github.com/git/git/blob/3ad8b5bf26362ac67c9020bf8c30eee54a84f56d/cache.h#L1011-L1012
+ EMPTY_TREE_ID = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'.freeze
BLANK_SHA = ('0' * 40).freeze
TAG_REF_PREFIX = "refs/tags/".freeze
BRANCH_REF_PREFIX = "refs/heads/".freeze
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/attributes_parser.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/attributes_parser.rb
index d8aeabb6c..08f4d7d4f 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/attributes_parser.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/attributes_parser.rb
@@ -3,12 +3,8 @@ module Gitlab
# Class for parsing Git attribute files and extracting the attributes for
# file patterns.
class AttributesParser
- def initialize(attributes_data)
+ def initialize(attributes_data = "")
@data = attributes_data || ""
-
- if @data.is_a?(File)
- @patterns = parse_file
- end
end
# Returns all the Git attributes for the given path.
@@ -28,7 +24,7 @@ module Gitlab
# Returns a Hash containing the file patterns and their attributes.
def patterns
- @patterns ||= parse_file
+ @patterns ||= parse_data
end
# Parses an attribute string.
@@ -91,8 +87,8 @@ module Gitlab
private
- # Parses the Git attributes file.
- def parse_file
+ # Parses the Git attributes file contents.
+ def parse_data
pairs = []
comment = '#'
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb
index 0fb82441b..fabcd46c8 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb
@@ -486,6 +486,8 @@ module Gitlab
end
def tree_entry(path)
+ return unless path.present?
+
@repository.gitaly_migrate(:commit_tree_entry) do |is_migrated|
if is_migrated
gitaly_tree_entry(path)
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/committer_with_hooks.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/committer_with_hooks.rb
new file mode 100644
index 000000000..a8a59f998
--- /dev/null
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/committer_with_hooks.rb
@@ -0,0 +1,47 @@
+module Gitlab
+ module Git
+ class CommitterWithHooks < Gollum::Committer
+ attr_reader :gl_wiki
+
+ def initialize(gl_wiki, options = {})
+ @gl_wiki = gl_wiki
+ super(gl_wiki.gollum_wiki, options)
+ end
+
+ def commit
+ # TODO: Remove after 10.8
+ return super unless allowed_to_run_hooks?
+
+ result = Gitlab::Git::OperationService.new(git_user, gl_wiki.repository).with_branch(
+ @wiki.ref,
+ start_branch_name: @wiki.ref
+ ) do |start_commit|
+ super(false)
+ end
+
+ result[:newrev]
+ rescue Gitlab::Git::HooksService::PreReceiveError => e
+ message = "Custom Hook failed: #{e.message}"
+ raise Gitlab::Git::Wiki::OperationError, message
+ end
+
+ private
+
+ # TODO: Remove after 10.8
+ def allowed_to_run_hooks?
+ @options[:user_id] != 0 && @options[:username].present?
+ end
+
+ def git_user
+ @git_user ||= Gitlab::Git::User.new(@options[:username],
+ @options[:name],
+ @options[:email],
+ gitlab_id)
+ end
+
+ def gitlab_id
+ Gitlab::GlId.gl_id_from_id_value(@options[:user_id])
+ end
+ end
+ end
+end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb
index a203587ae..b58296375 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/diff.rb
@@ -249,7 +249,7 @@ module Gitlab
if size >= SIZE_LIMIT
too_large!
- return true
+ return true # rubocop:disable Cop/AvoidReturnFromBlocks
end
end
end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/info_attributes.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/info_attributes.rb
deleted file mode 100644
index e79a44095..000000000
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/info_attributes.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# Gitaly note: JV: not sure what to make of this class. Why does it use
-# the full disk path of the repository to look up attributes This is
-# problematic in Gitaly, because Gitaly hides the full disk path to the
-# repository from gitlab-ce.
-
-module Gitlab
- module Git
- # Parses gitattributes at `$GIT_DIR/info/attributes`
- #
- # Unlike Rugged this parser only needs a single IO call (a call to `open`),
- # vastly reducing the time spent in extracting attributes.
- #
- # This class _only_ supports parsing the attributes file located at
- # `$GIT_DIR/info/attributes` as GitLab doesn't use any other files
- # (`.gitattributes` is copied to this particular path).
- #
- # Basic usage:
- #
- # attributes = Gitlab::Git::InfoAttributes.new(some_repo.path)
- #
- # attributes.attributes('README.md') # => { "eol" => "lf }
- class InfoAttributes
- delegate :attributes, :patterns, to: :parser
-
- # path - The path to the Git repository.
- def initialize(path)
- @repo_path = File.expand_path(path)
- end
-
- def parser
- @parser ||= begin
- if File.exist?(attributes_path)
- File.open(attributes_path, 'r') do |file_handle|
- AttributesParser.new(file_handle)
- end
- else
- AttributesParser.new("")
- end
- end
- end
-
- private
-
- def attributes_path
- @attributes_path ||= File.join(@repo_path, 'info/attributes')
- end
- end
- end
-end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/popen.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/popen.rb
index c1767046f..f9f24ecc4 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/popen.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/popen.rb
@@ -25,7 +25,9 @@ module Gitlab
stdin.close
if lazy_block
- return [lazy_block.call(stdout.lazy), 0]
+ cmd_output = lazy_block.call(stdout.lazy)
+ cmd_status = 0
+ break
else
cmd_output << stdout.read
end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/raw_diff_change.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/raw_diff_change.rb
new file mode 100644
index 000000000..eb3d88192
--- /dev/null
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/raw_diff_change.rb
@@ -0,0 +1,60 @@
+module Gitlab
+ module Git
+ # This class behaves like a struct with fields :blob_id, :blob_size, :operation, :old_path, :new_path
+ # All those fields are (binary) strings or integers
+ class RawDiffChange
+ attr_reader :blob_id, :blob_size, :old_path, :new_path, :operation
+
+ def initialize(raw_change)
+ parse(raw_change)
+ end
+
+ private
+
+ # Input data has the following format:
+ #
+ # When a file has been modified:
+ # 7e3e39ebb9b2bf433b4ad17313770fbe4051649c 669 M\tfiles/ruby/popen.rb
+ #
+ # When a file has been renamed:
+ # 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee
+ def parse(raw_change)
+ @blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4)
+ @operation = extract_operation
+ @old_path, @new_path = extract_paths(raw_paths)
+ end
+
+ def extract_paths(file_path)
+ case operation
+ when :renamed
+ file_path.split(/\t/)
+ when :deleted
+ [file_path, nil]
+ when :added
+ [nil, file_path]
+ else
+ [file_path, file_path]
+ end
+ end
+
+ def extract_operation
+ case @raw_operation&.first(1)
+ when 'A'
+ :added
+ when 'C'
+ :copied
+ when 'D'
+ :deleted
+ when 'M'
+ :modified
+ when 'R'
+ :renamed
+ when 'T'
+ :type_changed
+ else
+ :unknown
+ end
+ end
+ end
+ end
+end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb
index f1b575bd8..5a6e2e0b9 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb
@@ -9,6 +9,7 @@ module Gitlab
include Gitlab::Git::RepositoryMirroring
include Gitlab::Git::Popen
include Gitlab::EncodingHelper
+ include Gitlab::Utils::StrongMemoize
ALLOWED_OBJECT_DIRECTORIES_VARIABLES = %w[
GIT_OBJECT_DIRECTORY
@@ -75,9 +76,6 @@ module Gitlab
end
end
- # Full path to repo
- attr_reader :path
-
# Directory name of repo
attr_reader :name
@@ -96,22 +94,26 @@ module Gitlab
@relative_path = relative_path
@gl_repository = gl_repository
- storage_path = Gitlab.config.repositories.storages[@storage].legacy_disk_path
@gitlab_projects = Gitlab::Git::GitlabProjects.new(
storage,
relative_path,
global_hooks_path: Gitlab.config.gitlab_shell.hooks_path,
logger: Rails.logger
)
- @path = File.join(storage_path, @relative_path)
+
@name = @relative_path.split("/").last
- @attributes = Gitlab::Git::InfoAttributes.new(path)
end
def ==(other)
path == other.path
end
+ def path
+ @path ||= File.join(
+ Gitlab.config.repositories.storages[@storage].legacy_disk_path, @relative_path
+ )
+ end
+
# Default branch in the repository
def root_ref
@root_ref ||= gitaly_migrate(:root_ref) do |is_enabled|
@@ -140,12 +142,12 @@ module Gitlab
end
def exists?
- Gitlab::GitalyClient.migrate(:repository_exists, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |enabled|
+ Gitlab::GitalyClient.migrate(:repository_exists, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |enabled|
if enabled
gitaly_repository_client.exists?
else
circuit_breaker.perform do
- File.exist?(File.join(@path, 'refs'))
+ File.exist?(File.join(path, 'refs'))
end
end
end
@@ -230,13 +232,13 @@ module Gitlab
end
end
+ def expire_has_local_branches_cache
+ clear_memoization(:has_local_branches)
+ end
+
def has_local_branches?
- gitaly_migrate(:has_local_branches, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
- if is_enabled
- gitaly_repository_client.has_local_branches?
- else
- has_local_branches_rugged?
- end
+ strong_memoize(:has_local_branches) do
+ uncached_has_local_branches?
end
end
@@ -298,7 +300,8 @@ module Gitlab
#
# Ref names must start with `refs/`.
def ref_exists?(ref_name)
- gitaly_migrate(:ref_exists) do |is_enabled|
+ gitaly_migrate(:ref_exists,
+ status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_ref_exists?(ref_name)
else
@@ -559,6 +562,24 @@ module Gitlab
count_commits(from: from, to: to, **options)
end
+ # old_rev and new_rev are commit ID's
+ # the result of this method is an array of Gitlab::Git::RawDiffChange
+ def raw_changes_between(old_rev, new_rev)
+ result = []
+
+ circuit_breaker.perform do
+ Open3.pipeline_r(git_diff_cmd(old_rev, new_rev), format_git_cat_file_script, git_cat_file_cmd) do |last_stdout, wait_threads|
+ last_stdout.each_line { |line| result << ::Gitlab::Git::RawDiffChange.new(line.chomp!) }
+
+ if wait_threads.any? { |waiter| !waiter.value&.success? }
+ raise ::Gitlab::Git::Repository::GitError, "Unabled to obtain changes between #{old_rev} and #{new_rev}"
+ end
+ end
+ end
+
+ result
+ end
+
# Returns the SHA of the most recent common ancestor of +from+ and +to+
def merge_base(from, to)
gitaly_migrate(:merge_base) do |is_enabled|
@@ -993,11 +1014,32 @@ module Gitlab
raise InvalidRef
end
+ def info_attributes
+ return @info_attributes if @info_attributes
+
+ content =
+ gitaly_migrate(:get_info_attributes) do |is_enabled|
+ if is_enabled
+ gitaly_repository_client.info_attributes
+ else
+ attributes_path = File.join(File.expand_path(path), 'info', 'attributes')
+
+ if File.exist?(attributes_path)
+ File.read(attributes_path)
+ else
+ ""
+ end
+ end
+ end
+
+ @info_attributes = AttributesParser.new(content)
+ end
+
# Returns the Git attributes for the given file path.
#
# See `Gitlab::Git::Attributes` for more information.
def attributes(path)
- @attributes.attributes(path)
+ info_attributes.attributes(path)
end
def gitattribute(path, name)
@@ -1216,6 +1258,10 @@ module Gitlab
true
end
+ def create_from_snapshot(url, auth)
+ gitaly_repository_client.create_from_snapshot(url, auth)
+ end
+
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
gitaly_migrate(:rebase) do |is_enabled|
if is_enabled
@@ -1385,7 +1431,8 @@ module Gitlab
end
def branch_names_contains_sha(sha)
- gitaly_migrate(:branch_names_contains_sha) do |is_enabled|
+ gitaly_migrate(:branch_names_contains_sha,
+ status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_ref_client.branch_names_contains_sha(sha)
else
@@ -1395,7 +1442,8 @@ module Gitlab
end
def tag_names_contains_sha(sha)
- gitaly_migrate(:tag_names_contains_sha) do |is_enabled|
+ gitaly_migrate(:tag_names_contains_sha,
+ status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
if is_enabled
gitaly_ref_client.tag_names_contains_sha(sha)
else
@@ -1428,7 +1476,7 @@ module Gitlab
return [] if empty? || safe_query.blank?
- args = %W(ls-tree --full-tree -r #{ref || root_ref} --name-status | #{safe_query})
+ args = %W(ls-tree -r --name-status --full-tree #{ref || root_ref} -- #{safe_query})
run_git(args).first.lines.map(&:strip)
end
@@ -1517,6 +1565,16 @@ module Gitlab
private
+ def uncached_has_local_branches?
+ gitaly_migrate(:has_local_branches, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
+ if is_enabled
+ gitaly_repository_client.has_local_branches?
+ else
+ has_local_branches_rugged?
+ end
+ end
+ end
+
def local_write_ref(ref_path, ref, old_ref: nil, shell: true)
if shell
shell_write_ref(ref_path, ref, old_ref)
@@ -2461,6 +2519,35 @@ module Gitlab
result.to_s(16)
end
+
+ def build_git_cmd(*args)
+ object_directories = alternate_object_directories.join(File::PATH_SEPARATOR)
+
+ env = { 'PWD' => self.path }
+ env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories if object_directories.present?
+
+ [
+ env,
+ ::Gitlab.config.git.bin_path,
+ *args,
+ { chdir: self.path }
+ ]
+ end
+
+ def git_diff_cmd(old_rev, new_rev)
+ old_rev = old_rev == ::Gitlab::Git::BLANK_SHA ? ::Gitlab::Git::EMPTY_TREE_ID : old_rev
+
+ build_git_cmd('diff', old_rev, new_rev, '--raw')
+ end
+
+ def git_cat_file_cmd
+ format = '%(objectname) %(objectsize) %(rest)'
+ build_git_cmd('cat-file', "--batch-check=#{format}")
+ end
+
+ def format_git_cat_file_script
+ File.expand_path('../support/format-git-cat-file-input', __FILE__)
+ 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 dc424a433..8a01f92e2 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/repository_mirroring.rb
@@ -26,7 +26,7 @@ module Gitlab
# When the remote repo does not have tags.
if target.nil? || path.nil?
Rails.logger.info "Empty or invalid list of tags for remote: #{remote}. Output: #{output}"
- return []
+ break []
end
name = path.split('/', 3).last
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input b/ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input
new file mode 100755
index 000000000..2e93c646d
--- /dev/null
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+# This script formats the output of the `git diff <old_rev> <new_rev> --raw`
+# command so it can be processed by `git cat-file`
+
+# We need to convert this:
+# ":100644 100644 5f53439... 85bc2f9... R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee"
+# To:
+# "85bc2f9 R\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee"
+
+ARGF.each do |line|
+ _, _, old_blob_id, new_blob_id, rest = line.split(/\s/, 5)
+
+ old_blob_id.gsub!(/[^\h]/, '')
+ new_blob_id.gsub!(/[^\h]/, '')
+
+ # We can't pass '0000000...' to `git cat-file` given it will not return info about the deleted file
+ blob_id = new_blob_id =~ /\A0+\z/ ? old_blob_id : new_blob_id
+
+ $stdout.puts "#{blob_id} #{rest}"
+end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb
index 8d8282091..84a26fe4a 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb
+++ b/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb
@@ -2,10 +2,11 @@ module Gitlab
module Git
class Wiki
DuplicatePageError = Class.new(StandardError)
+ OperationError = Class.new(StandardError)
- CommitDetails = Struct.new(:name, :email, :message) do
+ CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do
def to_h
- { name: name, email: email, message: message }
+ { user_id: user_id, username: username, name: name, email: email, message: message }
end
end
PageBlob = Struct.new(:name)
@@ -140,6 +141,10 @@ module Gitlab
end
end
+ def gollum_wiki
+ @gollum_wiki ||= Gollum::Wiki.new(@repository.path)
+ end
+
private
# options:
@@ -158,10 +163,6 @@ module Gitlab
offset: options[:offset])
end
- def gollum_wiki
- @gollum_wiki ||= Gollum::Wiki.new(@repository.path)
- end
-
def gollum_page_by_path(page_path)
page_name = Gollum::Page.canonicalize_filename(page_path)
page_dir = File.split(page_path).first
@@ -201,12 +202,12 @@ module Gitlab
assert_type!(format, Symbol)
assert_type!(commit_details, CommitDetails)
- filename = File.basename(name)
- dir = (tmp_dir = File.dirname(name)) == '.' ? '' : tmp_dir
-
- gollum_wiki.write_page(filename, format, content, commit_details.to_h, dir)
+ with_committer_with_hooks(commit_details) do |committer|
+ filename = File.basename(name)
+ dir = (tmp_dir = File.dirname(name)) == '.' ? '' : tmp_dir
- nil
+ gollum_wiki.write_page(filename, format, content, { committer: committer }, dir)
+ end
rescue Gollum::DuplicatePageError => e
raise Gitlab::Git::Wiki::DuplicatePageError, e.message
end
@@ -214,24 +215,23 @@ module Gitlab
def gollum_delete_page(page_path, commit_details)
assert_type!(commit_details, CommitDetails)
- gollum_wiki.delete_page(gollum_page_by_path(page_path), commit_details.to_h)
- nil
+ with_committer_with_hooks(commit_details) do |committer|
+ gollum_wiki.delete_page(gollum_page_by_path(page_path), committer: committer)
+ end
end
def gollum_update_page(page_path, title, format, content, commit_details)
assert_type!(format, Symbol)
assert_type!(commit_details, CommitDetails)
- page = gollum_page_by_path(page_path)
- committer = Gollum::Committer.new(page.wiki, commit_details.to_h)
-
- # Instead of performing two renames if the title has changed,
- # the update_page will only update the format and content and
- # the rename_page will do anything related to moving/renaming
- gollum_wiki.update_page(page, page.name, format, content, committer: committer)
- gollum_wiki.rename_page(page, title, committer: committer)
- committer.commit
- nil
+ with_committer_with_hooks(commit_details) do |committer|
+ page = gollum_page_by_path(page_path)
+ # Instead of performing two renames if the title has changed,
+ # the update_page will only update the format and content and
+ # the rename_page will do anything related to moving/renaming
+ gollum_wiki.update_page(page, page.name, format, content, committer: committer)
+ gollum_wiki.rename_page(page, title, committer: committer)
+ end
end
def gollum_find_page(title:, version: nil, dir: nil)
@@ -288,6 +288,20 @@ module Gitlab
Gitlab::Git::WikiPage.new(wiki_page, version)
end
end
+
+ def committer_with_hooks(commit_details)
+ Gitlab::Git::CommitterWithHooks.new(self, commit_details.to_h)
+ end
+
+ def with_committer_with_hooks(commit_details, &block)
+ committer = committer_with_hooks(commit_details)
+
+ yield committer
+
+ committer.commit
+
+ nil
+ end
end
end
end