diff options
author | Paul Okstad <pokstad@gitlab.com> | 2020-12-15 20:16:31 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2020-12-15 20:16:31 +0300 |
commit | 774f20695cad6c5bfac26165f81ae70c54a90316 (patch) | |
tree | 4db7e86551a57ca1504040fa27d704cb9cb88e34 | |
parent | df687f0475b7077c5033bb9e33ad5a3e0c5af19e (diff) |
Update resolve conflict command to use gob over stdin
-rw-r--r-- | changelogs/unreleased/po-resolve-conflict-stdin-gob.yml | 5 | ||||
-rw-r--r-- | cmd/gitaly-git2go/resolve_conflicts.go | 19 | ||||
-rw-r--r-- | internal/git2go/resolve_conflicts.go | 41 |
3 files changed, 22 insertions, 43 deletions
diff --git a/changelogs/unreleased/po-resolve-conflict-stdin-gob.yml b/changelogs/unreleased/po-resolve-conflict-stdin-gob.yml new file mode 100644 index 000000000..b284adda7 --- /dev/null +++ b/changelogs/unreleased/po-resolve-conflict-stdin-gob.yml @@ -0,0 +1,5 @@ +--- +title: Update resolve conflict command to use gob over stdin +merge_request: 2903 +author: +type: fixed diff --git a/cmd/gitaly-git2go/resolve_conflicts.go b/cmd/gitaly-git2go/resolve_conflicts.go index c78b63716..ac7f81484 100644 --- a/cmd/gitaly-git2go/resolve_conflicts.go +++ b/cmd/gitaly-git2go/resolve_conflicts.go @@ -5,11 +5,11 @@ package main import ( "bytes" "context" + "encoding/gob" "errors" "flag" "fmt" "io" - "os" "strings" "time" @@ -19,18 +19,15 @@ import ( ) type resolveSubcommand struct { - request string } func (cmd *resolveSubcommand) Flags() *flag.FlagSet { - flags := flag.NewFlagSet("resolve", flag.ExitOnError) - flags.StringVar(&cmd.request, "request", "", "git2go.ResolveCommand") - return flags + return flag.NewFlagSet("resolve", flag.ExitOnError) } -func (cmd resolveSubcommand) Run(context.Context, io.Reader, io.Writer) error { - request, err := git2go.ResolveCommandFromSerialized(cmd.request) - if err != nil { +func (cmd resolveSubcommand) Run(_ context.Context, r io.Reader, w io.Writer) error { + var request git2go.ResolveCommand + if err := gob.NewDecoder(r).Decode(&request); err != nil { return err } @@ -193,11 +190,7 @@ func (cmd resolveSubcommand) Run(context.Context, io.Reader, io.Writer) error { }, } - if err := response.SerializeTo(os.Stdout); err != nil { - return fmt.Errorf("serializing response: %w", err) - } - - return nil + return gob.NewEncoder(w).Encode(response) } func mergeFileResult(odb *git.Odb, c git.IndexConflict) (*git.MergeFileResult, error) { diff --git a/internal/git2go/resolve_conflicts.go b/internal/git2go/resolve_conflicts.go index 42d9bf642..666d44f84 100644 --- a/internal/git2go/resolve_conflicts.go +++ b/internal/git2go/resolve_conflicts.go @@ -1,9 +1,10 @@ package git2go import ( + "bytes" "context" + "encoding/gob" "fmt" - "io" "gitlab.com/gitlab-org/gitaly/internal/git/conflict" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" @@ -12,28 +13,13 @@ import ( // ResolveCommand contains arguments to perform a merge commit and resolve any // conflicts produced from that merge commit type ResolveCommand struct { - MergeCommand `json:"merge_command"` - Resolutions []conflict.Resolution `json:"conflict_files"` + MergeCommand + Resolutions []conflict.Resolution } // ResolveResult returns information about the successful merge and resolution type ResolveResult struct { - MergeResult `json:"merge_result"` -} - -// ResolveResolveCommandFromSerialized deserializes a ResolveCommand and -// verifies the arguments are valid -func ResolveCommandFromSerialized(serialized string) (ResolveCommand, error) { - var request ResolveCommand - if err := deserialize(serialized, &request); err != nil { - return ResolveCommand{}, err - } - - if err := request.verify(); err != nil { - return ResolveCommand{}, fmt.Errorf("resolve: %w: %s", ErrInvalidArgument, err.Error()) - } - - return request, nil + MergeResult } // Run will attempt merging and resolving conflicts for the provided request @@ -42,25 +28,20 @@ func (r ResolveCommand) Run(ctx context.Context, cfg config.Cfg) (ResolveResult, return ResolveResult{}, fmt.Errorf("resolve: %w: %s", ErrInvalidArgument, err.Error()) } - serialized, err := serialize(r) - if err != nil { - return ResolveResult{}, err + input := &bytes.Buffer{} + if err := gob.NewEncoder(input).Encode(r); err != nil { + return ResolveResult{}, fmt.Errorf("resolve: %w", err) } - stdout, err := run(ctx, binaryPathFromCfg(cfg), nil, "resolve", "-request", serialized) + stdout, err := run(ctx, binaryPathFromCfg(cfg), input, "resolve") if err != nil { return ResolveResult{}, err } var response ResolveResult - if err := deserialize(stdout.String(), &response); err != nil { - return ResolveResult{}, err + if err := gob.NewDecoder(stdout).Decode(&response); err != nil { + return ResolveResult{}, fmt.Errorf("resolve: %w", err) } return response, nil } - -// SerializeTo serializes the resolve conflict and writes it to the writer -func (r ResolveResult) SerializeTo(w io.Writer) error { - return serializeTo(w, r) -} |