Skip to content

Commit

Permalink
Add new [lfs.server] and [lfs.client] config sectings for LFS_BATCH_S…
Browse files Browse the repository at this point in the history
…IZE configuration setting.

This contains two backwards-compatible changes:
* in the lfs http_client, the number of lfs oids requested per batch is loaded from lfs.client#BATCH_SIZE and defaulted to the previous value of 20
* in the lfs server/service, the max number of lfs oids allowed in a batch api request is loaded from lfs.server#MAX_BATCH_SIZE and defaults to 'nil' which equates to the previous behavior of 'infinite'

Signed-off-by: Royce Remer <royceremer@gmail.com>
  • Loading branch information
rremer authored and Royce Remer committed Oct 23, 2024
1 parent 7cf611d commit 1fef084
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
33 changes: 26 additions & 7 deletions modules/setting/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
"code.gitea.io/gitea/modules/generate"
)

// LFS represents the configuration for Git LFS
const LFSConfigSectionLegacyServer = "server"
const LFSConfigSectionServer = "lfs.server"
const LFSConfigSectionClient = "lfs.client"

// LFS represents the legacy configuration for Git LFS, to be migrated to LFSServer
var LFS = struct {
StartServer bool `ini:"LFS_START_SERVER"`
AllowPureSSH bool `ini:"LFS_ALLOW_PURE_SSH"`
Expand All @@ -22,11 +26,22 @@ var LFS = struct {
Storage *Storage
}{}

// LFSServer represents configuration for hosting Git LFS
var LFSServer = struct {
MaxBatchSize int `ini:MAX_BATCH_SIZE`
}{}

// LFSClient represents configuration for mirroring upstream Git LFS
var LFSClient = struct {
BatchSize int `ini:BATCH_SIZE`
}{}

func loadLFSFrom(rootCfg ConfigProvider) error {
sec := rootCfg.Section("server")
if err := sec.MapTo(&LFS); err != nil {
return fmt.Errorf("failed to map LFS settings: %v", err)
}
mustMapSetting(rootCfg, LFSConfigSectionServer, &LFSServer)
mustMapSetting(rootCfg, LFSConfigSectionClient, &LFSClient)
mustMapSetting(rootCfg, LFSConfigSectionLegacyServer, &LFS)

legacySec := rootCfg.Section(LFSConfigSectionLegacyServer)

lfsSec, _ := rootCfg.GetSection("lfs")

Expand All @@ -35,7 +50,7 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
// if these are removed, the warning will not be shown
deprecatedSetting(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")

if val := sec.Key("LFS_CONTENT_PATH").String(); val != "" {
if val := legacySec.Key("LFS_CONTENT_PATH").String(); val != "" {
if lfsSec == nil {
lfsSec = rootCfg.Section("lfs")
}
Expand All @@ -53,7 +68,11 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
LFS.LocksPagingNum = 50
}

LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
if LFSClient.BatchSize < 1 {
LFSClient.BatchSize = 20
}

LFS.HTTPAuthExpiry = legacySec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)

if !LFS.StartServer || !InstallLock {
return nil
Expand Down
16 changes: 16 additions & 0 deletions modules/setting/lfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,19 @@ STORAGE_TYPE = minio
assert.EqualValues(t, "gitea", LFS.Storage.MinioConfig.Bucket)
assert.EqualValues(t, "lfs/", LFS.Storage.MinioConfig.BasePath)
}

func Test_LFSClientServerConfigs(t *testing.T) {
iniStr := `
[lfs.server]
MAX_BATCH_SIZE = 100
[lfs.client]
# will default to 20
BATCH_SIZE = 0
`
cfg, err := NewConfigProviderFromData(iniStr)
assert.NoError(t, err)

assert.NoError(t, loadLFSFrom(cfg))
assert.EqualValues(t, 100, LFSServer.MaxBatchSize)
assert.EqualValues(t, 20, LFSClient.BatchSize)
}

0 comments on commit 1fef084

Please sign in to comment.