diff options
author | Toon Claes <toon@gitlab.com> | 2023-04-12 17:24:57 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2023-04-12 17:24:57 +0300 |
commit | 903650d6d1abe6e7e080cc7bc8d89218806264b5 (patch) | |
tree | a4a53b5448b10ab905bfb7efc261bab32dd60bf5 | |
parent | 0cea93e3c9f6648076ed36ee9218e003c6402c19 (diff) | |
parent | 52b6be49de233fbb8382e30e9d14f03818b97d6d (diff) |
Merge branch 'pks-git-command-factory-drop-sidecar-config' into 'master'
git: Remove sidecar Git configuration from command factory
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5636
Merged-by: Toon Claes <toon@gitlab.com>
Approved-by: Toon Claes <toon@gitlab.com>
Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
-rw-r--r-- | internal/git/command_factory.go | 52 | ||||
-rw-r--r-- | internal/git/command_factory_test.go | 22 | ||||
-rw-r--r-- | internal/git/gittest/intercepting_command_factory.go | 6 |
3 files changed, 0 insertions, 80 deletions
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index 6bef294a2..a637d96b4 100644 --- a/internal/git/command_factory.go +++ b/internal/git/command_factory.go @@ -38,11 +38,6 @@ type CommandFactory interface { HooksPath(context.Context) string // GitVersion returns the Git version used by the command factory. GitVersion(context.Context) (Version, error) - - // SidecarGitConfiguration returns the Git configuration is it should be used by the Ruby - // sidecar. This is a design wart and shouldn't ever be used outside of the context of the - // sidecar. - SidecarGitConfiguration(context.Context) ([]ConfigPair, error) } type execCommandFactoryConfig struct { @@ -611,53 +606,6 @@ func (cf *ExecCommandFactory) GlobalConfiguration(ctx context.Context) ([]Config return config, nil } -// SidecarGitConfiguration assembles the Git configuration as required by the Ruby sidecar. This -// includes global configuration, command-specific configuration for all commands executed in the -// sidecar, as well as configuration that was configured by the administrator in Gitaly's config. -// -// This function should not be used for anything else but the Ruby sidecar. -func (cf *ExecCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]ConfigPair, error) { - // Collect the global configuration that is specific to the current Git version... - globalConfig, err := cf.GlobalConfiguration(ctx) - if err != nil { - return nil, fmt.Errorf("getting global config: %w", err) - } - - var options []GlobalOption - for _, configPair := range globalConfig { - options = append(options, configPair) - } - - // ... as well as all configuration that exists for specific Git subcommands. The sidecar - // 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. - configPairs := make([]ConfigPair, 0, len(options)+len(cf.cfg.Git.Config)) - for _, option := range options { - configPair, ok := option.(ConfigPair) - if !ok { - continue - } - - configPairs = append(configPairs, configPair) - } - - // Lastly, we also apply the Git configuration as set by the administrator in Gitaly's - // config. Note that we do not check for conflicts here: administrators should be able to - // override whatever is configured by Gitaly. - for _, configEntry := range cf.cfg.Git.Config { - configPairs = append(configPairs, ConfigPair{ - Key: configEntry.Key, - Value: configEntry.Value, - }) - } - - return configPairs, nil -} - func (cf *ExecCommandFactory) trace2Finalizer(manager *trace2.Manager) func(context.Context, *command.Command) { return func(ctx context.Context, cmd *command.Command) { manager.Finish(ctx) diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 677221d48..955ac513d 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -654,28 +654,6 @@ func TestExecCommandFactory_config(t *testing.T) { require.Equal(t, expectedEnv, strings.Split(strings.TrimSpace(stdout.String()), "\n")) } -func TestExecCommandFactory_SidecarGitConfiguration(t *testing.T) { - t.Parallel() - - ctx := testhelper.Context(t) - cfg := testcfg.Build(t) - - cfg.Git.Config = []config.GitConfig{ - {Key: "custom.key", Value: "injected"}, - } - - configPairs, err := gittest.NewCommandFactory(t, cfg).SidecarGitConfiguration(ctx) - require.NoError(t, err) - require.Equal(t, []git.ConfigPair{ - {Key: "gc.auto", Value: "0"}, - {Key: "core.autocrlf", Value: "input"}, - {Key: "core.useReplaceRefs", Value: "false"}, - {Key: "core.fsync", Value: "objects,derived-metadata,reference"}, - {Key: "core.fsyncMethod", Value: "fsync"}, - {Key: "custom.key", Value: "injected"}, - }, configPairs) -} - // TestFsckConfiguration tests the hardcoded configuration of the // git fsck subcommand generated through the command factory. func TestFsckConfiguration(t *testing.T) { diff --git a/internal/git/gittest/intercepting_command_factory.go b/internal/git/gittest/intercepting_command_factory.go index 8f229927c..cda216b4e 100644 --- a/internal/git/gittest/intercepting_command_factory.go +++ b/internal/git/gittest/intercepting_command_factory.go @@ -141,9 +141,3 @@ func (f *InterceptingCommandFactory) GitVersion(ctx context.Context) (git.Versio } return f.realCommandFactory.GitVersion(ctx) } - -// SidecarGitConfiguration returns the Ruby sidecar Git configuration as computed by the actual Git -// command factory. -func (f *InterceptingCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]git.ConfigPair, error) { - return f.interceptingCommandFactory.SidecarGitConfiguration(ctx) -} |