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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-16 08:48:50 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-05-17 10:38:52 +0300
commitde8bbc7c68a20578e9c83fd7b7b4e48d4ea31112 (patch)
tree11fcb2b9e90d094b78de9be5fb85e07022af68e0
parent4350c670b8a4ec9113d60b928d25508c38e04afa (diff)
ruby: Read `HEAD` via Ruggedpks-ruby-reduce-usage-of-git
The `#head_symbolic_ref` function is using git-symbolic-ref(1) to read the repo's `HEAD` symbolic reference. We're slowly phasing out all executions of the Git command line though, and we can easily implement it via Rugged. Convert the function to use Rugged to read the reference. This allows us to get rid of the now-unused `#run_git` function, and furthermore we don't have to inject configuration for git-symbolic-ref(1) into the sidecar anymore.
-rw-r--r--internal/git/command_factory.go7
-rw-r--r--ruby/lib/gitlab/git/repository.rb16
2 files changed, 6 insertions, 17 deletions
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 653bde385..9f9cb5c81 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -533,10 +533,9 @@ func (cf *ExecCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]Co
}
// ... as well as all configuration that exists for specific Git subcommands. The sidecar
- // only executes git-symbolic-ref(1) and git-update-ref(1) nowadays, and this set of
- // commands is not expected to grow anymore. So while really intimate with how the sidecar
- // does this, it is good enough until we finally remove it.
- options = append(options, commandDescriptions["symbolic-ref"].opts...)
+ // only executes git-update-ref(1) nowadays, and this set of commands is not expected to
+ // grow anymore. So while really intimate with how the sidecar does this, it is good enough
+ // until we finally remove it.
options = append(options, commandDescriptions["update-ref"].opts...)
// Convert the `GlobalOption`s into `ConfigPair`s.
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index b2b0c1fb9..cbe5bde19 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -250,25 +250,15 @@ module Gitlab
end
def head_symbolic_ref
- message, status = run_git(%w[symbolic-ref HEAD])
+ head = rugged.ref('HEAD')
- return 'main' if status.nonzero?
+ return 'main' if head.type != :symbolic
- Ref.extract_branch_name(message.squish)
+ Ref.extract_branch_name(head.target_id)
end
private
- def run_git(args, chdir: path, env: {}, nice: false, include_stderr: false, lazy_block: nil, &block)
- cmd = [Gitlab.config.git.bin_path, *args]
- cmd.unshift("nice") if nice
-
- object_directories = alternate_object_directories
- env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories.join(File::PATH_SEPARATOR) if object_directories.any?
-
- popen(cmd, chdir, env, include_stderr: include_stderr, lazy_block: lazy_block, &block)
- end
-
def branches_filter(filter: nil, sort_by: nil)
branches = rugged.branches.each(filter).map do |rugged_ref|
begin