Skip to content

Commit b6afdc2

Browse files
rremerRoyce Remer
authored and
Royce Remer
committed
Add new [lfs.server] and [lfs.client] config settings for batch sizes.
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' This fixes #32306 Signed-off-by: Royce Remer <[email protected]>
1 parent 7cf611d commit b6afdc2

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

modules/setting/lfs.go

+26-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import (
1010
"code.gitea.io/gitea/modules/generate"
1111
)
1212

13-
// LFS represents the configuration for Git LFS
13+
const LFSConfigSectionLegacyServer = "server"
14+
const LFSConfigSectionServer = "lfs.server"
15+
const LFSConfigSectionClient = "lfs.client"
16+
17+
// LFS represents the legacy configuration for Git LFS, to be migrated to LFSServer
1418
var LFS = struct {
1519
StartServer bool `ini:"LFS_START_SERVER"`
1620
AllowPureSSH bool `ini:"LFS_ALLOW_PURE_SSH"`
@@ -22,11 +26,22 @@ var LFS = struct {
2226
Storage *Storage
2327
}{}
2428

29+
// LFSServer represents configuration for hosting Git LFS
30+
var LFSServer = struct {
31+
MaxBatchSize int `ini:MAX_BATCH_SIZE`
32+
}{}
33+
34+
// LFSClient represents configuration for mirroring upstream Git LFS
35+
var LFSClient = struct {
36+
BatchSize int `ini:BATCH_SIZE`
37+
}{}
38+
2539
func loadLFSFrom(rootCfg ConfigProvider) error {
26-
sec := rootCfg.Section("server")
27-
if err := sec.MapTo(&LFS); err != nil {
28-
return fmt.Errorf("failed to map LFS settings: %v", err)
29-
}
40+
mustMapSetting(rootCfg, LFSConfigSectionServer, &LFSServer)
41+
mustMapSetting(rootCfg, LFSConfigSectionClient, &LFSClient)
42+
mustMapSetting(rootCfg, LFSConfigSectionLegacyServer, &LFS)
43+
44+
legacySec := rootCfg.Section(LFSConfigSectionLegacyServer)
3045

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

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

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

56-
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
71+
if LFSClient.BatchSize < 1 {
72+
LFSClient.BatchSize = 20
73+
}
74+
75+
LFS.HTTPAuthExpiry = legacySec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
5776

5877
if !LFS.StartServer || !InstallLock {
5978
return nil

modules/setting/lfs_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,19 @@ STORAGE_TYPE = minio
9999
assert.EqualValues(t, "gitea", LFS.Storage.MinioConfig.Bucket)
100100
assert.EqualValues(t, "lfs/", LFS.Storage.MinioConfig.BasePath)
101101
}
102+
103+
func Test_LFSClientServerConfigs(t *testing.T) {
104+
iniStr := `
105+
[lfs.server]
106+
MAX_BATCH_SIZE = 100
107+
[lfs.client]
108+
# will default to 20
109+
BATCH_SIZE = 0
110+
`
111+
cfg, err := NewConfigProviderFromData(iniStr)
112+
assert.NoError(t, err)
113+
114+
assert.NoError(t, loadLFSFrom(cfg))
115+
assert.EqualValues(t, 100, LFSServer.MaxBatchSize)
116+
assert.EqualValues(t, 20, LFSClient.BatchSize)
117+
}

services/lfs/server.go

+6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ func BatchHandler(ctx *context.Context) {
179179
return
180180
}
181181

182+
batchSize := len(br.Objects)
183+
if setting.LFSServer.MaxBatchSize != 0 && batchSize > setting.LFSServer.MaxBatchSize {
184+
writeStatus(ctx, http.StatusRequestEntityTooLarge)
185+
return
186+
}
187+
182188
contentStore := lfs_module.NewContentStore()
183189

184190
var responseObjects []*lfs_module.ObjectResponse

0 commit comments

Comments
 (0)