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>2020-07-30 15:56:15 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-08-31 10:46:36 +0300
commit4fe271875f66c3f8a5981f8d4afc6aa95ef14885 (patch)
tree1ec4b4aae5be97b95ba4acddd5be7248500f136f /cmd/gitaly-git2go
parent2c9cb511bc487c3da056536ef0adafff5202c89d (diff)
git2go: Implement support for subcommands
In order to keep the next commit focussed on actual merge logic, let's prepare the infrastructure to support subcommands in the gitaly-git2go binary.
Diffstat (limited to 'cmd/gitaly-git2go')
-rw-r--r--cmd/gitaly-git2go/main.go47
-rw-r--r--cmd/gitaly-git2go/merge.go19
2 files changed, 55 insertions, 11 deletions
diff --git a/cmd/gitaly-git2go/main.go b/cmd/gitaly-git2go/main.go
index bc25dc67c..cdd168482 100644
--- a/cmd/gitaly-git2go/main.go
+++ b/cmd/gitaly-git2go/main.go
@@ -3,23 +3,48 @@
package main
import (
+ "flag"
+ "fmt"
"os"
-
- git "github.com/libgit2/git2go/v30"
)
+type subcmd interface {
+ Flags() *flag.FlagSet
+ Run() error
+}
+
+var subcommands = map[string]subcmd{
+ "merge": &mergeSubcommand{},
+}
+
+const programName = "gitaly-git2go"
+
+func fatalf(format string, args ...interface{}) {
+ fmt.Fprintf(os.Stderr, format+"\n", args...)
+ os.Exit(1)
+}
+
func main() {
- repo, err := git.OpenRepository(".")
- if err != nil {
- os.Exit(1)
+ flags := flag.NewFlagSet(programName, flag.ExitOnError)
+ flags.Parse(os.Args)
+
+ if flags.NArg() < 2 {
+ fatalf("missing subcommand")
+ }
+
+ subcmd, ok := subcommands[flags.Arg(1)]
+ if !ok {
+ fatalf("unknown subcommand: %q", flags.Arg(1))
}
- defer repo.Free()
- head, err := repo.Head()
- if err != nil {
- os.Exit(1)
+ subcmdFlags := subcmd.Flags()
+ subcmdFlags.Parse(flags.Args()[2:])
+
+ if subcmdFlags.NArg() != 0 {
+ fatalf("%s: trailing arguments", subcmdFlags.Name())
}
- defer head.Free()
- println(head.Target().String())
+ if err := subcmd.Run(); err != nil {
+ fatalf("%s: %s", subcmdFlags.Name(), err)
+ }
}
diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go
new file mode 100644
index 000000000..1d2f48c4b
--- /dev/null
+++ b/cmd/gitaly-git2go/merge.go
@@ -0,0 +1,19 @@
+// +build static,system_libgit2
+
+package main
+
+import (
+ "flag"
+)
+
+type mergeSubcommand struct {
+}
+
+func (cmd *mergeSubcommand) Flags() *flag.FlagSet {
+ flags := flag.NewFlagSet("merge", flag.ExitOnError)
+ return flags
+}
+
+func (cmd *mergeSubcommand) Run() error {
+ return nil
+}