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
path: root/cmd
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-08-26 13:28:14 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-08-30 12:10:58 +0300
commit3021571efead4725ef8395e43fc5a0361cb0dd20 (patch)
tree76fe90ed22ae47d0c355ac89d2347c1ae0d46618 /cmd
parent43712287b0b811a55840b90ac4889103428526f4 (diff)
gitaly-git2go: Support gob in the merge subcommand
Back when we have started implementing RPCs via gitaly-git2go, the initial implementations were all using JSON as representation for inputs and outputs. At a later point we noticed that this makes it hard to return typed errors, which is why later subcommands have shifted to using gob encoders. The merge subcommand is the first command we have written, and thus it also uses JSON encoding, facing the exact error handling issue mentioned above. We want to extend the command to return information about conflicting files though, which would ideally be part of the returned error type. Refactor the subcommand to optionally support gob as encoding: if the command is called with no JSON request, then we instead use gob. While this seems kind of cheap, it's easier than adding a separate flag and should always provide expected results: we never call the command without a request, and the request cannot ever be empty given that it's a JSON-encoded struct.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitaly-git2go/merge.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go
index 8fc6df65c..cd7fb4673 100644
--- a/cmd/gitaly-git2go/merge.go
+++ b/cmd/gitaly-git2go/merge.go
@@ -4,6 +4,7 @@ package main
import (
"context"
+ "encoding/gob"
"errors"
"flag"
"fmt"
@@ -26,8 +27,16 @@ func (cmd *mergeSubcommand) Flags() *flag.FlagSet {
return flags
}
-func (cmd *mergeSubcommand) Run(_ context.Context, _ io.Reader, w io.Writer) error {
- request, err := git2go.MergeCommandFromSerialized(cmd.request)
+func (cmd *mergeSubcommand) Run(_ context.Context, r io.Reader, w io.Writer) error {
+ useGob := cmd.request == ""
+
+ var err error
+ var request git2go.MergeCommand
+ if useGob {
+ err = gob.NewDecoder(r).Decode(&request)
+ } else {
+ request, err = git2go.MergeCommandFromSerialized(cmd.request)
+ }
if err != nil {
return err
}
@@ -37,6 +46,13 @@ func (cmd *mergeSubcommand) Run(_ context.Context, _ io.Reader, w io.Writer) err
}
commitID, err := merge(request)
+ if useGob {
+ return gob.NewEncoder(w).Encode(git2go.Result{
+ CommitID: commitID,
+ Error: git2go.SerializableError(err),
+ })
+ }
+
if err != nil {
return err
}