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-10-12 10:59:15 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-10-12 11:00:24 +0300
commitcc310e28e86c2701c6fecbaf595f7802e20b2959 (patch)
treeda069e1102885fb5dbbec959c8107ee9eee191f4
parent97f1c689ed7a7b9e915ae0afb06e797831f68ca2 (diff)
git2go: Extract `lookupCommit` into its own file
The generic function `lookupCommit()` used to lookup a commit by reference is currently implemented in "merge.go", which is also its only user. As we're about to add additional users, let's extract this function into a standalone file to help discoverability.
-rw-r--r--cmd/gitaly-git2go/merge.go19
-rw-r--r--cmd/gitaly-git2go/util.go28
2 files changed, 28 insertions, 19 deletions
diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go
index 3f07a51ab..dab99c4bc 100644
--- a/cmd/gitaly-git2go/merge.go
+++ b/cmd/gitaly-git2go/merge.go
@@ -23,25 +23,6 @@ func (cmd *mergeSubcommand) Flags() *flag.FlagSet {
return flags
}
-func lookupCommit(repo *git.Repository, ref string) (*git.Commit, error) {
- object, err := repo.RevparseSingle(ref)
- if err != nil {
- return nil, fmt.Errorf("could not lookup reference: %w", err)
- }
-
- peeled, err := object.Peel(git.ObjectCommit)
- if err != nil {
- return nil, fmt.Errorf("could not peel reference: %w", err)
- }
-
- commit, err := peeled.AsCommit()
- if err != nil {
- return nil, fmt.Errorf("could not cast to commit: %w", err)
- }
-
- return commit, nil
-}
-
func sanitizeSignatureInfo(info string) string {
return strings.Map(func(r rune) rune {
switch r {
diff --git a/cmd/gitaly-git2go/util.go b/cmd/gitaly-git2go/util.go
new file mode 100644
index 000000000..d580582cd
--- /dev/null
+++ b/cmd/gitaly-git2go/util.go
@@ -0,0 +1,28 @@
+// +build static,system_libgit2
+
+package main
+
+import (
+ "fmt"
+
+ git "github.com/libgit2/git2go/v30"
+)
+
+func lookupCommit(repo *git.Repository, ref string) (*git.Commit, error) {
+ object, err := repo.RevparseSingle(ref)
+ if err != nil {
+ return nil, fmt.Errorf("could not lookup reference: %w", err)
+ }
+
+ peeled, err := object.Peel(git.ObjectCommit)
+ if err != nil {
+ return nil, fmt.Errorf("could not peel reference: %w", err)
+ }
+
+ commit, err := peeled.AsCommit()
+ if err != nil {
+ return nil, fmt.Errorf("could not cast to commit: %w", err)
+ }
+
+ return commit, nil
+}