diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-05 10:42:53 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-05 10:42:53 +0300 |
commit | 4325481ab92a44ae5de5f58e126fe1202512998a (patch) | |
tree | 7afd7ecb9bb3464b9f7e94b00f64cb4eceaa8695 /internal/git2go | |
parent | 516b9e1684879959073a19cfe7e3a024ee2f95ec (diff) |
gitaly-git2go: Remove the now-unused command
Remove the now-unused gitaly-git2o command as well as its supporting
infrastructure.
Diffstat (limited to 'internal/git2go')
-rw-r--r-- | internal/git2go/executor.go | 142 | ||||
-rw-r--r-- | internal/git2go/featureflags.go | 22 | ||||
-rw-r--r-- | internal/git2go/featureflags_test.go | 72 | ||||
-rw-r--r-- | internal/git2go/rebase.go | 42 | ||||
-rw-r--r-- | internal/git2go/serialization.go | 102 | ||||
-rw-r--r-- | internal/git2go/signature.go | 9 | ||||
-rw-r--r-- | internal/git2go/testhelper_test.go | 11 |
7 files changed, 0 insertions, 400 deletions
diff --git a/internal/git2go/executor.go b/internal/git2go/executor.go deleted file mode 100644 index f5cca8252..000000000 --- a/internal/git2go/executor.go +++ /dev/null @@ -1,142 +0,0 @@ -package git2go - -import ( - "bytes" - "context" - "encoding/gob" - "errors" - "fmt" - "io" - "strings" - - "github.com/sirupsen/logrus" - "gitlab.com/gitlab-org/gitaly/v16/internal/command" - "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag" - "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/alternates" - "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" - "gitlab.com/gitlab-org/labkit/correlation" -) - -var ( - // ErrInvalidArgument is returned in case the merge arguments are invalid. - ErrInvalidArgument = errors.New("invalid parameters") - - // BinaryName is the name of the gitaly-git2go binary. - BinaryName = "gitaly-git2go" -) - -// Executor executes gitaly-git2go. -type Executor struct { - binaryPath string - signingKey string - gitCmdFactory git.CommandFactory - locator storage.Locator - logger logrus.FieldLogger - logFormat, logLevel string -} - -// NewExecutor returns a new gitaly-git2go executor using binaries as configured in the given -// configuration. -func NewExecutor(cfg config.Cfg, gitCmdFactory git.CommandFactory, locator storage.Locator, logger logrus.FieldLogger) *Executor { - return &Executor{ - binaryPath: cfg.BinaryPath(BinaryName), - signingKey: cfg.Git.SigningKey, - gitCmdFactory: gitCmdFactory, - locator: locator, - logger: logger, - logFormat: cfg.Logging.Format, - logLevel: cfg.Logging.Level, - } -} - -func (b *Executor) run(ctx context.Context, repo storage.Repository, stdin io.Reader, subcmd string, args ...string) (*bytes.Buffer, error) { - repoPath, err := b.locator.GetRepoPath(repo) - if err != nil { - return nil, fmt.Errorf("gitaly-git2go: %w", err) - } - - var enabledFeatureFlags, disabledFeatureFlags []string - - for flag, value := range featureflag.FromContext(ctx) { - switch value { - case true: - enabledFeatureFlags = append(enabledFeatureFlags, flag.MetadataKey()) - case false: - disabledFeatureFlags = append(disabledFeatureFlags, flag.MetadataKey()) - } - } - - env := alternates.Env(repoPath, repo.GetGitObjectDirectory(), repo.GetGitAlternateObjectDirectories()) - env = append(env, b.gitCmdFactory.GetExecutionEnvironment(ctx).EnvironmentVariables...) - - // Construct a log writer that we pass to gitaly-git2go. Note that this is not exactly pretty: the output - // generated by the logger is not going to be parsed, but will be written to the log without any change as log - // message. - // - // Previously, we would have written these messages to `logrus.Logger.Out` directly. But we have refactored our - // code to get rid of the global logger instance, and thus we cannot access that field anymore. Given that the - // git2go executor is going away next release anyway, let's just live with this ugly workaround here. We still - // have visibility into what the process is doing, but with a bit less comfort. That seems like an acceptable - // tradeoff in order to get rid of the global logger altogether. - logWriter := b.logger.WithField("component", "git2go."+subcmd).Writer() - defer logWriter.Close() - - args = append([]string{ - "-log-format", b.logFormat, - "-log-level", b.logLevel, - "-correlation-id", correlation.ExtractFromContext(ctx), - "-enabled-feature-flags", strings.Join(enabledFeatureFlags, ","), - "-disabled-feature-flags", strings.Join(disabledFeatureFlags, ","), - subcmd, - }, args...) - - var stdout bytes.Buffer - cmd, err := command.New(ctx, append([]string{b.binaryPath}, args...), - command.WithStdin(stdin), - command.WithStdout(&stdout), - command.WithStderr(logWriter), - command.WithEnvironment(env), - command.WithCommandName("gitaly-git2go", subcmd), - ) - if err != nil { - return nil, err - } - - if err := cmd.Wait(); err != nil { - return nil, err - } - - return &stdout, nil -} - -// runWithGob runs the specified gitaly-git2go cmd with the request gob-encoded -// as input and returns the commit ID as string or an error. -func (b *Executor) runWithGob(ctx context.Context, repo storage.Repository, cmd string, request interface{}) (git.ObjectID, error) { - input := &bytes.Buffer{} - if err := gob.NewEncoder(input).Encode(request); err != nil { - return "", fmt.Errorf("%s: %w", cmd, err) - } - - output, err := b.run(ctx, repo, input, cmd) - if err != nil { - return "", fmt.Errorf("%s: %w", cmd, err) - } - - var result Result - if err := gob.NewDecoder(output).Decode(&result); err != nil { - return "", fmt.Errorf("%s: %w", cmd, err) - } - - if result.Err != nil { - return "", fmt.Errorf("%s: %w", cmd, result.Err) - } - - commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID) - if err != nil { - return "", fmt.Errorf("could not parse commit ID: %w", err) - } - - return commitID, nil -} diff --git a/internal/git2go/featureflags.go b/internal/git2go/featureflags.go deleted file mode 100644 index bfde6867b..000000000 --- a/internal/git2go/featureflags.go +++ /dev/null @@ -1,22 +0,0 @@ -package git2go - -// FeatureFlag is a feature flag state as seen by the `gitaly-git2go featureflag` test subcommand. -type FeatureFlag struct { - // MetadataKey is the metadata key of the feature flag. - MetadataKey string - // Name is the name of the feature flag. - Name string - // Value is the value of the feature flag. - Value bool -} - -// FeatureFlags is a struct only used by tests to confirm that feature flags are -// being properly propagated from the git2go Executor to the gitaly-git2go -// binary -type FeatureFlags struct { - // Flags is the set of feature flags observed by the command. - Flags []FeatureFlag - // Err is set if an error occurred. Err must exist on all gob serialized - // results so that any error can be returned. - Err error -} diff --git a/internal/git2go/featureflags_test.go b/internal/git2go/featureflags_test.go deleted file mode 100644 index db2a35992..000000000 --- a/internal/git2go/featureflags_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package git2go - -import ( - "context" - "encoding/gob" - "testing" - - "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo" - "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" - "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" - "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" -) - -func (b *Executor) FeatureFlags(ctx context.Context, repo storage.Repository) ([]FeatureFlag, error) { - output, err := b.run(ctx, repo, nil, "feature-flags") - if err != nil { - return nil, err - } - - var result FeatureFlags - if err := gob.NewDecoder(output).Decode(&result); err != nil { - return nil, err - } - - if result.Err != nil { - return nil, result.Err - } - - return result.Flags, err -} - -var ( - featureA = featureflag.NewFeatureFlag("feature_a", "", "", false) - featureB = featureflag.NewFeatureFlag("feature_b", "", "", true) -) - -func TestExecutor_explicitFeatureFlags(t *testing.T) { - testhelper.NewFeatureSets(featureA, featureB).Run(t, testExecutorFeatureFlags) -} - -func testExecutorFeatureFlags(t *testing.T, ctx context.Context) { - cfg := testcfg.Build(t) - testcfg.BuildGitalyGit2Go(t, cfg) - - repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ - SkipCreationViaService: true, - }) - - repo := localrepo.NewTestRepo(t, cfg, repoProto) - - executor := NewExecutor(cfg, gittest.NewCommandFactory(t, cfg), config.NewLocator(cfg), testhelper.SharedLogger(t)) - - flags, err := executor.FeatureFlags(ctx, repo) - require.NoError(t, err) - - require.Subset(t, flags, []FeatureFlag{ - { - Name: "feature_a", - MetadataKey: "gitaly-feature-feature-a", - Value: featureA.IsEnabled(ctx), - }, - { - Name: "feature_b", - MetadataKey: "gitaly-feature-feature-b", - Value: featureB.IsEnabled(ctx), - }, - }, flags) -} diff --git a/internal/git2go/rebase.go b/internal/git2go/rebase.go deleted file mode 100644 index 3bdc0e9e6..000000000 --- a/internal/git2go/rebase.go +++ /dev/null @@ -1,42 +0,0 @@ -package git2go - -import ( - "context" - - "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" -) - -// RebaseCommand contains parameters to rebase a branch. -type RebaseCommand struct { - // Repository is the path to execute rebase in. - Repository string - // Committer contains the the committer signature. - Committer Signature - // BranchName is the branch that is rebased. Deprecated, can be removed in the next release. - BranchName string - // UpstreamRevision is the revision where the branch is rebased onto. Deprecated, can be - // removed in the next release. - UpstreamRevision string - // CommitID is the object ID of the commit that shall be rebased. Deprecates BranchName. - CommitID git.ObjectID - // UpstreamCommitID is the object ID of the commit which is considered to be the - // upstream branch. This parameter determines both the commit onto which we're - // about to rebase, which is the merge base of the upstream commit and rebased - // commit, and which commits should be rebased, which is the commit range - // upstream..commit. Deprecates the UpstreamRevision. - UpstreamCommitID git.ObjectID - // SkipEmptyCommits will cause commits which have already been applied on the target branch - // and which are thus empty to be skipped. If unset, empty commits will cause the rebase to - // fail. - SkipEmptyCommits bool - // SigningKey is a path to the key to sign commit using OpenPGP - SigningKey string -} - -// Rebase performs the rebase via gitaly-git2go -func (b *Executor) Rebase(ctx context.Context, repo storage.Repository, r RebaseCommand) (git.ObjectID, error) { - r.SigningKey = b.signingKey - - return b.runWithGob(ctx, repo, "rebase", r) -} diff --git a/internal/git2go/serialization.go b/internal/git2go/serialization.go deleted file mode 100644 index a1454e916..000000000 --- a/internal/git2go/serialization.go +++ /dev/null @@ -1,102 +0,0 @@ -package git2go - -import ( - "encoding/gob" - "errors" - "fmt" - "reflect" -) - -func init() { - for typeToRegister := range registeredTypes { - gob.Register(reflect.Zero(typeToRegister).Interface()) - } -} - -var registeredTypes = map[reflect.Type]struct{}{ - reflect.TypeOf(wrapError{}): {}, - reflect.TypeOf(HasConflictsError{}): {}, - reflect.TypeOf(ConflictingFilesError{}): {}, - reflect.TypeOf(EmptyError{}): {}, - reflect.TypeOf(CommitNotFoundError{}): {}, -} - -// Result is the serialized result. -type Result struct { - // CommitID is the result of the call. - CommitID string - // Err is set if an error occurred. Err must exist on all gob serialized - // results so that all errors can be returned. - Err error -} - -// wrapError is used to serialize wrapped errors as fmt.wrapError type only has -// private fields and can't be serialized via gob. It's also used to serialize unregistered -// error types by serializing only their error message. -type wrapError struct { - Message string - Err error -} - -func (err wrapError) Error() string { return err.Message } - -func (err wrapError) Unwrap() error { return err.Err } - -// HasConflictsError is used when a change, for example a revert, could not be -// applied due to a conflict. -type HasConflictsError struct{} - -func (err HasConflictsError) Error() string { - return "could not apply due to conflicts" -} - -// ConflictingFilesError is an error raised when there are conflicting files. -type ConflictingFilesError struct { - // ConflictingFiles is the set of files which have conflicts. - ConflictingFiles []string -} - -func (err ConflictingFilesError) Error() string { - return "there are conflicting files" -} - -// EmptyError indicates the command, for example cherry-pick, did result in no -// changes, so the result is empty. -type EmptyError struct{} - -func (err EmptyError) Error() string { - return "could not apply because the result was empty" -} - -// CommitNotFoundError indicates that the given commit rev could not be found. -type CommitNotFoundError struct { - // Revision used to lookup the commit - Revision string -} - -func (err CommitNotFoundError) Error() string { - return fmt.Sprintf("commit not found: %q", err.Revision) -} - -// SerializableError returns an error that is Gob serializable. -// Registered types are serialized directly. Unregistered types -// are transformed in to an opaque error using their error message. -// Wrapped errors remain unwrappable. -func SerializableError(err error) error { - if err == nil { - return nil - } - - if unwrappedErr := errors.Unwrap(err); unwrappedErr != nil { - return wrapError{ - Message: err.Error(), - Err: SerializableError(unwrappedErr), - } - } - - if _, ok := registeredTypes[reflect.TypeOf(err)]; !ok { - return wrapError{Message: err.Error()} - } - - return err -} diff --git a/internal/git2go/signature.go b/internal/git2go/signature.go deleted file mode 100644 index 1d66ed5e0..000000000 --- a/internal/git2go/signature.go +++ /dev/null @@ -1,9 +0,0 @@ -package git2go - -import "gitlab.com/gitlab-org/gitaly/v16/internal/git" - -// Signature represents a commits signature, synced from internal/git. -type Signature = git.Signature - -// NewSignature creates a new sanitized signature, syned from internal/git. -var NewSignature = git.NewSignature diff --git a/internal/git2go/testhelper_test.go b/internal/git2go/testhelper_test.go deleted file mode 100644 index f4298b718..000000000 --- a/internal/git2go/testhelper_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package git2go - -import ( - "testing" - - "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" -) - -func TestMain(m *testing.M) { - testhelper.Run(m) -} |