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-12-09 12:33:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-12-10 10:16:42 +0300
commitb6e9bc45400931c0cd172f0f8682283cb8b945da (patch)
tree472f4087da7d07d0a660d28ce7d8b668879447b0
parente657f69e8bb63f3b41f54b33072dab52c8669083 (diff)
transaction: Unify logic to extract optional transaction metadata
The logic to optionally extract transaction metadata from the context is duplicated across the `internal/gitaly/service/operations` and `internal/git` packages. Let's deduplicate it and move it into a central place next to the other metadata-related functions.
-rw-r--r--internal/git/hooks_options.go19
-rw-r--r--internal/gitaly/service/operations/update_with_hooks.go19
-rw-r--r--internal/praefect/metadata/transaction.go19
3 files changed, 21 insertions, 36 deletions
diff --git a/internal/git/hooks_options.go b/internal/git/hooks_options.go
index 23fe094e7..a091351d1 100644
--- a/internal/git/hooks_options.go
+++ b/internal/git/hooks_options.go
@@ -37,7 +37,7 @@ func (cc *cmdCfg) configureHooks(ctx context.Context, repo *gitalypb.Repository,
return errors.New("hooks already configured")
}
- transaction, praefect, err := transactionFromContext(ctx)
+ transaction, praefect, err := metadata.TransactionMetadataFromContext(ctx)
if err != nil {
return err
}
@@ -99,20 +99,3 @@ func receivePackHookEnv(ctx context.Context, cc *cmdCfg, cfg config.Cfg, req Rec
return env, nil
}
-
-func transactionFromContext(ctx context.Context) (*metadata.Transaction, *metadata.PraefectServer, error) {
- transaction, err := metadata.TransactionFromContext(ctx)
- if err != nil {
- if errors.Is(err, metadata.ErrTransactionNotFound) {
- return nil, nil, nil
- }
- return nil, nil, err
- }
-
- praefect, err := metadata.PraefectFromContext(ctx)
- if err != nil {
- return nil, nil, err
- }
-
- return &transaction, praefect, nil
-}
diff --git a/internal/gitaly/service/operations/update_with_hooks.go b/internal/gitaly/service/operations/update_with_hooks.go
index a723dbb26..7a7537a6a 100644
--- a/internal/gitaly/service/operations/update_with_hooks.go
+++ b/internal/gitaly/service/operations/update_with_hooks.go
@@ -37,7 +37,7 @@ func (s *Server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re
return err
}
- transaction, praefect, err := transactionFromContext(ctx)
+ transaction, praefect, err := metadata.TransactionMetadataFromContext(ctx)
if err != nil {
return err
}
@@ -102,20 +102,3 @@ func (s *Server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re
return nil
}
-
-func transactionFromContext(ctx context.Context) (*metadata.Transaction, *metadata.PraefectServer, error) {
- transaction, err := metadata.TransactionFromContext(ctx)
- if err != nil {
- if err != metadata.ErrTransactionNotFound {
- return nil, nil, err
- }
- return nil, nil, nil
- }
-
- praefect, err := metadata.PraefectFromContext(ctx)
- if err != nil {
- return nil, nil, err
- }
-
- return &transaction, praefect, nil
-}
diff --git a/internal/praefect/metadata/transaction.go b/internal/praefect/metadata/transaction.go
index ca41d1d4b..3663b1183 100644
--- a/internal/praefect/metadata/transaction.go
+++ b/internal/praefect/metadata/transaction.go
@@ -129,3 +129,22 @@ func TransactionFromEnv(envvars []string) (Transaction, error) {
return transactionFromSerialized(transactionEnv)
}
+
+// TransactionMetadataFromContext extracts transaction-related metadata from
+// the given context. No error is returned in case no transaction was found.
+func TransactionMetadataFromContext(ctx context.Context) (*Transaction, *PraefectServer, error) {
+ transaction, err := TransactionFromContext(ctx)
+ if err != nil {
+ if err != ErrTransactionNotFound {
+ return nil, nil, err
+ }
+ return nil, nil, nil
+ }
+
+ praefect, err := PraefectFromContext(ctx)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ return &transaction, praefect, nil
+}