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>2022-05-31 15:13:36 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-10 09:34:46 +0300
commitaa0f408dcd190dbd958e26fd23869cb0fc37efe3 (patch)
treef80cde60092615a6e60be820a1b6bf8d8b25d0ef
parent98145dc5f816f6f554697f16190f5736e33eddec (diff)
cmd/gitaly-lfs-smudge: Introduce driver types
Until now, gitaly-lfs-smudge only supports converting a single LFS pointer into its object. This is inefficient though, and Git has an alternative protocol that allows us to convert multiple LFS pointers in a single session via the long-running filter protocol. Introduce a new driver type so that we can easily discern which type of filter Git is expecting: either the old one-shot "filter", or the newer "process" type. For now, this functionality is neither implemented nor used.
-rw-r--r--cmd/gitaly-lfs-smudge/main.go15
-rw-r--r--internal/git/smudge/config.go29
-rw-r--r--internal/git/smudge/config_test.go2
-rw-r--r--internal/gitaly/service/repository/archive.go1
4 files changed, 38 insertions, 9 deletions
diff --git a/cmd/gitaly-lfs-smudge/main.go b/cmd/gitaly-lfs-smudge/main.go
index 7e4ba6fc2..c5ce5e4cb 100644
--- a/cmd/gitaly-lfs-smudge/main.go
+++ b/cmd/gitaly-lfs-smudge/main.go
@@ -72,9 +72,16 @@ func run(environment []string, out io.Writer, in io.Reader) error {
return fmt.Errorf("loading configuration: %w", err)
}
- if err := filter(ctx, cfg, out, in); err != nil {
- return fmt.Errorf("running smudge filter: %w", err)
- }
+ switch cfg.DriverType {
+ case smudge.DriverTypeFilter:
+ if err := filter(ctx, cfg, out, in); err != nil {
+ return fmt.Errorf("running smudge filter: %w", err)
+ }
- return nil
+ return nil
+ case smudge.DriverTypeProcess:
+ return fmt.Errorf("process driver type not yet supported")
+ default:
+ return fmt.Errorf("unknown driver type: %v", cfg.DriverType)
+ }
}
diff --git a/internal/git/smudge/config.go b/internal/git/smudge/config.go
index aa3d10a5b..d7f5a48d0 100644
--- a/internal/git/smudge/config.go
+++ b/internal/git/smudge/config.go
@@ -15,6 +15,18 @@ import (
// value of this environment variable should be the JSON-encoded `Config` struct.
const ConfigEnvironmentKey = "GITALY_LFS_SMUDGE_CONFIG"
+// DriverType determines the type of the smudge filter.
+type DriverType int
+
+const (
+ // DriverTypeFilter indicates that the smudge filter is to be run once per object. This is
+ // the current default but will be phased out eventually in favor of DriverTypeProcess.
+ DriverTypeFilter = DriverType(0)
+ // DriverTypeProcess is a long-running smudge filter that can process multiple objects in
+ // one session. See gitattributes(5), "Long Running Filter Process".
+ DriverTypeProcess = DriverType(1)
+)
+
// Config is the configuration used to run gitaly-lfs-smudge. It must be injected via environment
// variables.
type Config struct {
@@ -26,6 +38,8 @@ type Config struct {
Gitlab config.Gitlab `json:"gitlab"`
// TLS contains configuration for setting up a TLS-encrypted connection to Rails.
TLS config.TLS `json:"tls"`
+ // DriverType is the type of the smudge driver that should be used.
+ DriverType DriverType `json:"driver_type"`
}
// ConfigFromEnvironment loads the Config structure from the set of given environment variables.
@@ -82,8 +96,15 @@ func (c Config) Environment() (string, error) {
// GitConfiguration returns the Git configuration required to run the smudge filter.
func (c Config) GitConfiguration(cfg config.Cfg) (git.ConfigPair, error) {
- return git.ConfigPair{
- Key: "filter.lfs.smudge",
- Value: filepath.Join(cfg.BinDir, "gitaly-lfs-smudge"),
- }, nil
+ switch c.DriverType {
+ case DriverTypeFilter:
+ return git.ConfigPair{
+ Key: "filter.lfs.smudge",
+ Value: filepath.Join(cfg.BinDir, "gitaly-lfs-smudge"),
+ }, nil
+ case DriverTypeProcess:
+ return git.ConfigPair{}, fmt.Errorf("processor driver type not yet supported")
+ default:
+ return git.ConfigPair{}, fmt.Errorf("unknown driver type: %v", c.DriverType)
+ }
}
diff --git a/internal/git/smudge/config_test.go b/internal/git/smudge/config_test.go
index d988bf16c..e2299b763 100644
--- a/internal/git/smudge/config_test.go
+++ b/internal/git/smudge/config_test.go
@@ -169,5 +169,5 @@ func TestConfig_Environment(t *testing.T) {
env, err := cfg.Environment()
require.NoError(t, err)
- require.Equal(t, `GITALY_LFS_SMUDGE_CONFIG={"gl_repository":"repo","gitlab":{"url":"https://example.com","relative_url_root":"gitlab","http_settings":{"read_timeout":1,"user":"user","password":"correcthorsebatterystaple","ca_file":"/ca/file","ca_path":"/ca/path","self_signed_cert":true},"secret_file":"/secret/path"},"tls":{"cert_path":"/cert/path","key_path":"/key/path"}}`, env)
+ require.Equal(t, `GITALY_LFS_SMUDGE_CONFIG={"gl_repository":"repo","gitlab":{"url":"https://example.com","relative_url_root":"gitlab","http_settings":{"read_timeout":1,"user":"user","password":"correcthorsebatterystaple","ca_file":"/ca/file","ca_path":"/ca/path","self_signed_cert":true},"secret_file":"/secret/path"},"tls":{"cert_path":"/cert/path","key_path":"/key/path"},"driver_type":0}`, env)
}
diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go
index 040fa4aba..8cb7947df 100644
--- a/internal/gitaly/service/repository/archive.go
+++ b/internal/gitaly/service/repository/archive.go
@@ -200,6 +200,7 @@ func (s *server) handleArchive(p archiveParams) error {
GlRepository: p.in.GetRepository().GetGlRepository(),
Gitlab: s.cfg.Gitlab,
TLS: s.cfg.TLS,
+ DriverType: smudge.DriverTypeFilter,
}
smudgeEnv, err := smudgeCfg.Environment()