Skip to content

Commit b594773

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix suggestions for issues (go-gitea#32380) refactor: remove redundant err declarations (go-gitea#32381) Fix the missing menu in organization project view page (go-gitea#32313) Fix toAbsoluteLocaleDate and add more tests (go-gitea#32387) Respect UI.ExploreDefaultSort setting again (go-gitea#32357) Fix absolute-date (go-gitea#32375) Fix undefined errors on Activity page (go-gitea#32378) Add new [lfs_client].BATCH_SIZE and [server].LFS_MAX_BATCH_SIZE config settings. (go-gitea#32307) remove unused call to $.HeadRepo in view_title template (go-gitea#32317) Fix clean tmp dir (go-gitea#32360) Optimize branch protection rule loading (go-gitea#32280) Suggestions for issues (go-gitea#32327) Migrate vue components to setup (go-gitea#32329)
2 parents 07e84c7 + a4a121c commit b594773

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1072
-862
lines changed

build/generate-emoji.go

-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func (e Emoji) MarshalJSON() ([]byte, error) {
5353
}
5454

5555
func main() {
56-
var err error
57-
5856
flag.Parse()
5957

6058
// generate data
@@ -83,8 +81,6 @@ var replacer = strings.NewReplacer(
8381
var emojiRE = regexp.MustCompile(`\{Emoji:"([^"]*)"`)
8482

8583
func generate() ([]byte, error) {
86-
var err error
87-
8884
// load gemoji data
8985
res, err := http.Get(gemojiURL)
9086
if err != nil {

custom/conf/app.example.ini

+8
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ RUN_USER = ; git
324324
;; Maximum number of locks returned per page
325325
;LFS_LOCKS_PAGING_NUM = 50
326326
;;
327+
;; When clients make lfs batch requests, reject them if there are more pointers than this number
328+
;; zero means 'unlimited'
329+
;LFS_MAX_BATCH_SIZE = 0
330+
;;
327331
;; Allow graceful restarts using SIGHUP to fork
328332
;ALLOW_GRACEFUL_RESTARTS = true
329333
;;
@@ -2638,6 +2642,10 @@ LEVEL = Info
26382642
;; override the azure blob base path if storage type is azureblob
26392643
;AZURE_BLOB_BASE_PATH = lfs/
26402644

2645+
;[lfs_client]
2646+
;; When mirroring an upstream lfs endpoint, limit the number of pointers in each batch request to this number
2647+
;BATCH_SIZE = 20
2648+
26412649
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26422650
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26432651
;; settings for packages, will override storage setting

models/git/lfs.go

-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ var ErrLFSObjectNotExist = db.ErrNotExist{Resource: "LFS Meta object"}
136136
// NewLFSMetaObject stores a given populated LFSMetaObject structure in the database
137137
// if it is not already present.
138138
func NewLFSMetaObject(ctx context.Context, repoID int64, p lfs.Pointer) (*LFSMetaObject, error) {
139-
var err error
140-
141139
ctx, committer, err := db.TxContext(ctx)
142140
if err != nil {
143141
return nil, err

models/git/protected_branch.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,20 @@ func IsRuleNameSpecial(ruleName string) bool {
8484
}
8585

8686
func (protectBranch *ProtectedBranch) loadGlob() {
87-
if protectBranch.globRule == nil {
88-
var err error
89-
protectBranch.globRule, err = glob.Compile(protectBranch.RuleName, '/')
90-
if err != nil {
91-
log.Warn("Invalid glob rule for ProtectedBranch[%d]: %s %v", protectBranch.ID, protectBranch.RuleName, err)
92-
protectBranch.globRule = glob.MustCompile(glob.QuoteMeta(protectBranch.RuleName), '/')
93-
}
94-
protectBranch.isPlainName = !IsRuleNameSpecial(protectBranch.RuleName)
87+
if protectBranch.isPlainName || protectBranch.globRule != nil {
88+
return
89+
}
90+
// detect if it is not glob
91+
if !IsRuleNameSpecial(protectBranch.RuleName) {
92+
protectBranch.isPlainName = true
93+
return
94+
}
95+
// now we load the glob
96+
var err error
97+
protectBranch.globRule, err = glob.Compile(protectBranch.RuleName, '/')
98+
if err != nil {
99+
log.Warn("Invalid glob rule for ProtectedBranch[%d]: %s %v", protectBranch.ID, protectBranch.RuleName, err)
100+
protectBranch.globRule = glob.MustCompile(glob.QuoteMeta(protectBranch.RuleName), '/')
95101
}
96102
}
97103

models/git/protected_banch_list_test.go models/git/protected_branch_list_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,32 @@ func TestBranchRuleMatchPriority(t *testing.T) {
7474
}
7575
}
7676
}
77+
78+
func TestBranchRuleSort(t *testing.T) {
79+
in := []*ProtectedBranch{{
80+
RuleName: "b",
81+
CreatedUnix: 1,
82+
}, {
83+
RuleName: "b/*",
84+
CreatedUnix: 3,
85+
}, {
86+
RuleName: "a/*",
87+
CreatedUnix: 2,
88+
}, {
89+
RuleName: "c",
90+
CreatedUnix: 0,
91+
}, {
92+
RuleName: "a",
93+
CreatedUnix: 4,
94+
}}
95+
expect := []string{"c", "b", "a", "a/*", "b/*"}
96+
97+
pbr := ProtectedBranchRules(in)
98+
pbr.sort()
99+
100+
var got []string
101+
for i := range pbr {
102+
got = append(got, pbr[i].RuleName)
103+
}
104+
assert.Equal(t, expect, got)
105+
}

models/issues/label_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ func TestGetLabelsByOrgID(t *testing.T) {
229229
testSuccess(3, "reversealphabetically", []int64{4, 3})
230230
testSuccess(3, "default", []int64{3, 4})
231231

232-
var err error
233-
_, err = issues_model.GetLabelsByOrgID(db.DefaultContext, 0, "leastissues", db.ListOptions{})
232+
_, err := issues_model.GetLabelsByOrgID(db.DefaultContext, 0, "leastissues", db.ListOptions{})
234233
assert.True(t, issues_model.IsErrOrgLabelNotExist(err))
235234

236235
_, err = issues_model.GetLabelsByOrgID(db.DefaultContext, -1, "leastissues", db.ListOptions{})

modules/charset/charset_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ func TestMaybeRemoveBOM(t *testing.T) {
4040

4141
func TestToUTF8(t *testing.T) {
4242
resetDefaultCharsetsOrder()
43-
var res string
44-
var err error
4543

4644
// Note: golang compiler seems so behave differently depending on the current
4745
// locale, so some conversions might behave differently. For that reason, we don't
4846
// depend on particular conversions but in expected behaviors.
4947

50-
res, err = ToUTF8([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
48+
res, err := ToUTF8([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
5149
assert.NoError(t, err)
5250
assert.Equal(t, "ABC", res)
5351

modules/git/repo_index.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,35 @@ func (repo *Repository) readTreeToIndex(id ObjectID, indexFilename ...string) er
5050
}
5151

5252
// ReadTreeToTemporaryIndex reads a treeish to a temporary index file
53-
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpDir string, cancel context.CancelFunc, err error) {
53+
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (tmpIndexFilename, tmpDir string, cancel context.CancelFunc, err error) {
54+
defer func() {
55+
// if error happens and there is a cancel function, do clean up
56+
if err != nil && cancel != nil {
57+
cancel()
58+
cancel = nil
59+
}
60+
}()
61+
62+
removeDirFn := func(dir string) func() { // it can't use the return value "tmpDir" directly because it is empty when error occurs
63+
return func() {
64+
if err := util.RemoveAll(dir); err != nil {
65+
log.Error("failed to remove tmp index dir: %v", err)
66+
}
67+
}
68+
}
69+
5470
tmpDir, err = os.MkdirTemp("", "index")
5571
if err != nil {
56-
return filename, tmpDir, cancel, err
72+
return "", "", nil, err
5773
}
5874

59-
filename = filepath.Join(tmpDir, ".tmp-index")
60-
cancel = func() {
61-
err := util.RemoveAll(tmpDir)
62-
if err != nil {
63-
log.Error("failed to remove tmp index file: %v", err)
64-
}
65-
}
66-
err = repo.ReadTreeToIndex(treeish, filename)
75+
tmpIndexFilename = filepath.Join(tmpDir, ".tmp-index")
76+
cancel = removeDirFn(tmpDir)
77+
err = repo.ReadTreeToIndex(treeish, tmpIndexFilename)
6778
if err != nil {
68-
defer cancel()
69-
return "", "", func() {}, err
79+
return "", "", cancel, err
7080
}
71-
return filename, tmpDir, cancel, err
81+
return tmpIndexFilename, tmpDir, cancel, err
7282
}
7383

7484
// EmptyIndex empties the index

modules/lfs/http_client.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import (
1616
"code.gitea.io/gitea/modules/json"
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/modules/proxy"
19+
"code.gitea.io/gitea/modules/setting"
1920
)
2021

21-
const httpBatchSize = 20
22-
2322
// HTTPClient is used to communicate with the LFS server
2423
// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md
2524
type HTTPClient struct {
@@ -30,7 +29,7 @@ type HTTPClient struct {
3029

3130
// BatchSize returns the preferred size of batchs to process
3231
func (c *HTTPClient) BatchSize() int {
33-
return httpBatchSize
32+
return setting.LFSClient.BatchSize
3433
}
3534

3635
func newHTTPClient(endpoint *url.URL, httpTransport *http.Transport) *HTTPClient {

modules/markup/markdown/goldmark.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ func (r *HTMLRenderer) renderIcon(w util.BufWriter, source []byte, node ast.Node
213213
return ast.WalkContinue, nil
214214
}
215215

216-
var err error
217-
_, err = w.WriteString(fmt.Sprintf(`<i class="icon %s"></i>`, name))
216+
_, err := w.WriteString(fmt.Sprintf(`<i class="icon %s"></i>`, name))
218217
if err != nil {
219218
return ast.WalkStop, err
220219
}

modules/setting/lfs.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@ import (
1010
"code.gitea.io/gitea/modules/generate"
1111
)
1212

13-
// LFS represents the configuration for Git LFS
13+
// LFS represents the server-side configuration for Git LFS.
14+
// Ideally these options should be in a section like "[lfs_server]",
15+
// but they are in "[server]" section due to historical reasons.
16+
// Could be refactored in the future while keeping backwards compatibility.
1417
var LFS = struct {
1518
StartServer bool `ini:"LFS_START_SERVER"`
1619
AllowPureSSH bool `ini:"LFS_ALLOW_PURE_SSH"`
1720
JWTSecretBytes []byte `ini:"-"`
1821
HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
1922
MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
2023
LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
24+
MaxBatchSize int `ini:"LFS_MAX_BATCH_SIZE"`
2125

2226
Storage *Storage
2327
}{}
2428

29+
// LFSClient represents configuration for Gitea's LFS clients, for example: mirroring upstream Git LFS
30+
var LFSClient = struct {
31+
BatchSize int `ini:"BATCH_SIZE"`
32+
}{}
33+
2534
func loadLFSFrom(rootCfg ConfigProvider) error {
35+
mustMapSetting(rootCfg, "lfs_client", &LFSClient)
36+
37+
mustMapSetting(rootCfg, "server", &LFS)
2638
sec := rootCfg.Section("server")
27-
if err := sec.MapTo(&LFS); err != nil {
28-
return fmt.Errorf("failed to map LFS settings: %v", err)
29-
}
3039

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

@@ -53,6 +62,10 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
5362
LFS.LocksPagingNum = 50
5463
}
5564

65+
if LFSClient.BatchSize < 1 {
66+
LFSClient.BatchSize = 20
67+
}
68+
5669
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
5770

5871
if !LFS.StartServer || !InstallLock {

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+
[server]
106+
LFS_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, LFS.MaxBatchSize)
116+
assert.EqualValues(t, 20, LFSClient.BatchSize)
117+
}

package-lock.json

+15-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@citation-js/plugin-software-formats": "0.6.1",
1111
"@github/markdown-toolbar-element": "2.2.3",
1212
"@github/relative-time-element": "4.4.3",
13-
"@github/text-expander-element": "2.7.1",
13+
"@github/text-expander-element": "2.8.0",
1414
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
1515
"@primer/octicons": "19.11.0",
1616
"@silverwind/vue3-calendar-heatmap": "2.0.6",
@@ -39,13 +39,13 @@
3939
"monaco-editor": "0.51.0",
4040
"monaco-editor-webpack-plugin": "7.1.0",
4141
"pdfobject": "2.3.0",
42+
"perfect-debounce": "1.0.0",
4243
"postcss": "8.4.41",
4344
"postcss-loader": "8.1.1",
4445
"postcss-nesting": "13.0.0",
4546
"sortablejs": "1.15.2",
4647
"swagger-ui-dist": "5.17.14",
4748
"tailwindcss": "3.4.10",
48-
"temporal-polyfill": "0.2.5",
4949
"throttle-debounce": "5.0.2",
5050
"tinycolor2": "1.6.0",
5151
"tippy.js": "6.3.7",

0 commit comments

Comments
 (0)