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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 14 additions & 8 deletions
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 renamed to models/git/protected_branch_list_test.go

Lines changed: 29 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 23 additions & 13 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 1 addition & 2 deletions
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
}

0 commit comments

Comments
 (0)