Skip to content

Commit 6dc5a9a

Browse files
authored
Merge branch 'main' into fix-gpg-signature-error-page
2 parents 304c65a + ca67c5a commit 6dc5a9a

Some content is hidden

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

51 files changed

+247
-305
lines changed

.air.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ tmp_dir = ".air"
55
cmd = "make backend"
66
bin = "gitea"
77
include_ext = ["go", "tmpl"]
8-
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata"]
9-
include_dir = ["cmd", "models", "modules", "options", "routers", "services", "templates"]
8+
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata", "models/fixtures", "models/migrations/fixtures", "modules/migration/file_format_testdata", "modules/avatar/identicon/testdata"]
9+
include_dir = ["cmd", "models", "modules", "options", "routers", "services"]
1010
exclude_regex = ["_test.go$", "_gen.go$"]

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ be reviewed by two maintainers and must pass the automatic tests.
441441
Code that you contribute should use the standard copyright header:
442442

443443
```
444-
// Copyright 2022 The Gitea Authors. All rights reserved.
444+
// Copyright <year> The Gitea Authors. All rights reserved.
445445
// SPDX-License-Identifier: MIT
446446
447447
```

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ watch-frontend: node-check node_modules
359359

360360
.PHONY: watch-backend
361361
watch-backend: go-check
362-
$(GO) run $(AIR_PACKAGE) -c .air.toml
362+
GITEA_RUN_MODE=dev $(GO) run $(AIR_PACKAGE) -c .air.toml
363363

364364
.PHONY: test
365365
test: test-frontend test-backend

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,9 @@ ROUTER = console
957957
;; Don't allow download source archive files from UI
958958
;DISABLE_DOWNLOAD_SOURCE_ARCHIVES = false
959959

960+
;; Allow fork repositories without maximum number limit
961+
;ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT = true
962+
960963
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
961964
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
962965
;[repository.editor]

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ In addition there is _`StaticRootPath`_ which can be set as a built-in at build
112112
- `ALLOW_ADOPTION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to adopt unadopted repositories
113113
- `ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES`: **false**: Allow non-admin users to delete unadopted repositories
114114
- `DISABLE_DOWNLOAD_SOURCE_ARCHIVES`: **false**: Don't allow download source archive files from UI
115+
- `ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT`: **true**: Allow fork repositories without maximum number limit
115116

116117
### Repository - Editor (`repository.editor`)
117118

@@ -239,6 +240,10 @@ The following configuration set `Content-Type: application/vnd.android.package-a
239240
- `NOTICE_PAGING_NUM`: **25**: Number of notices that are shown in one page.
240241
- `ORG_PAGING_NUM`: **50**: Number of organizations that are shown in one page.
241242

243+
### UI - User (`ui.user`)
244+
245+
- `REPO_PAGING_NUM`: **15**: Number of repos that are shown in one page.
246+
242247
### UI - Metadata (`ui.meta`)
243248

244249
- `AUTHOR`: **Gitea - Git with a cup of tea**: Author meta tag of the homepage.

models/activities/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (a *Action) GetRefLink() string {
272272
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
273273
case strings.HasPrefix(a.RefName, git.TagPrefix):
274274
return a.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.TagPrefix))
275-
case len(a.RefName) == 40 && git.IsValidSHAPattern(a.RefName):
275+
case len(a.RefName) == git.SHAFullLength && git.IsValidSHAPattern(a.RefName):
276276
return a.GetRepoLink() + "/src/commit/" + a.RefName
277277
default:
278278
// FIXME: we will just assume it's a branch - this was the old way - at some point we may want to enforce that there is always a ref here.

models/git/commit_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ func NewCommitStatus(opts NewCommitStatusOptions) error {
279279
return fmt.Errorf("NewCommitStatus[%s, %s]: no user specified", repoPath, opts.SHA)
280280
}
281281

282+
if _, err := git.NewIDFromString(opts.SHA); err != nil {
283+
return fmt.Errorf("NewCommitStatus[%s, %s]: invalid sha: %w", repoPath, opts.SHA, err)
284+
}
285+
282286
ctx, committer, err := db.TxContext(db.DefaultContext)
283287
if err != nil {
284288
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err)

models/user/user.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ func (u *User) CanEditGitHook() bool {
275275
return !setting.DisableGitHooks && (u.IsAdmin || u.AllowGitHook)
276276
}
277277

278+
// CanForkRepo returns if user login can fork a repository
279+
// It checks especially that the user can create repos, and potentially more
280+
func (u *User) CanForkRepo() bool {
281+
if setting.Repository.AllowForkWithoutMaximumLimit {
282+
return true
283+
}
284+
return u.CanCreateRepo()
285+
}
286+
278287
// CanImportLocal returns true if user can migrate repository by local path.
279288
func (u *User) CanImportLocal() bool {
280289
if !setting.ImportLocalPaths || u == nil {

modules/context/api.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ func (ctx *APIContext) CheckForOTP() {
219219
func APIAuth(authMethod auth_service.Method) func(*APIContext) {
220220
return func(ctx *APIContext) {
221221
// Get user from session if logged in.
222-
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
222+
var err error
223+
ctx.Doer, err = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
224+
if err != nil {
225+
ctx.Error(http.StatusUnauthorized, "APIAuth", err)
226+
return
227+
}
228+
223229
if ctx.Doer != nil {
224230
if ctx.Locale.Language() != ctx.Doer.Language {
225231
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
@@ -387,7 +393,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
387393
return
388394
}
389395
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
390-
} else if len(refName) == 40 {
396+
} else if len(refName) == git.SHAFullLength {
391397
ctx.Repo.CommitID = refName
392398
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
393399
if err != nil {

modules/context/context.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,13 @@ func getCsrfOpts() CsrfOptions {
662662
// Auth converts auth.Auth as a middleware
663663
func Auth(authMethod auth.Method) func(*Context) {
664664
return func(ctx *Context) {
665-
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
665+
var err error
666+
ctx.Doer, err = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
667+
if err != nil {
668+
log.Error("Failed to verify user %v: %v", ctx.Req.RemoteAddr, err)
669+
ctx.Error(http.StatusUnauthorized, "Verify")
670+
return
671+
}
666672
if ctx.Doer != nil {
667673
if ctx.Locale.Language() != ctx.Doer.Language {
668674
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)

modules/context/repo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
817817
}
818818
// For legacy and API support only full commit sha
819819
parts := strings.Split(path, "/")
820-
if len(parts) > 0 && len(parts[0]) == 40 {
820+
if len(parts) > 0 && len(parts[0]) == git.SHAFullLength {
821821
ctx.Repo.TreePath = strings.Join(parts[1:], "/")
822822
return parts[0]
823823
}
@@ -853,7 +853,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
853853
return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsTagExist)
854854
case RepoRefCommit:
855855
parts := strings.Split(path, "/")
856-
if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= 40 {
856+
if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= git.SHAFullLength {
857857
ctx.Repo.TreePath = strings.Join(parts[1:], "/")
858858
return parts[0]
859859
}
@@ -962,7 +962,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
962962
return
963963
}
964964
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
965-
} else if len(refName) >= 7 && len(refName) <= 40 {
965+
} else if len(refName) >= 7 && len(refName) <= git.SHAFullLength {
966966
ctx.Repo.IsViewCommit = true
967967
ctx.Repo.CommitID = refName
968968

@@ -972,7 +972,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
972972
return
973973
}
974974
// If short commit ID add canonical link header
975-
if len(refName) < 40 {
975+
if len(refName) < git.SHAFullLength {
976976
ctx.RespHeader().Set("Link", fmt.Sprintf("<%s>; rel=\"canonical\"",
977977
util.URLJoin(setting.AppURL, strings.Replace(ctx.Req.URL.RequestURI(), util.PathEscapeSegments(refName), url.PathEscape(ctx.Repo.Commit.ID.String()), 1))))
978978
}

modules/git/repo_attribute.go

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12-
"strconv"
13-
"strings"
1412

1513
"code.gitea.io/gitea/modules/log"
1614
)
@@ -288,102 +286,6 @@ func (wr *nulSeparatedAttributeWriter) Close() error {
288286
return nil
289287
}
290288

291-
type lineSeparatedAttributeWriter struct {
292-
tmp []byte
293-
attributes chan attributeTriple
294-
closed chan struct{}
295-
}
296-
297-
func (wr *lineSeparatedAttributeWriter) Write(p []byte) (n int, err error) {
298-
l := len(p)
299-
300-
nlIdx := bytes.IndexByte(p, '\n')
301-
for nlIdx >= 0 {
302-
wr.tmp = append(wr.tmp, p[:nlIdx]...)
303-
304-
if len(wr.tmp) == 0 {
305-
// This should not happen
306-
if len(p) > nlIdx+1 {
307-
wr.tmp = wr.tmp[:0]
308-
p = p[nlIdx+1:]
309-
nlIdx = bytes.IndexByte(p, '\n')
310-
continue
311-
} else {
312-
return l, nil
313-
}
314-
}
315-
316-
working := attributeTriple{}
317-
if wr.tmp[0] == '"' {
318-
sb := new(strings.Builder)
319-
remaining := string(wr.tmp[1:])
320-
for len(remaining) > 0 {
321-
rn, _, tail, err := strconv.UnquoteChar(remaining, '"')
322-
if err != nil {
323-
if len(remaining) > 2 && remaining[0] == '"' && remaining[1] == ':' && remaining[2] == ' ' {
324-
working.Filename = sb.String()
325-
wr.tmp = []byte(remaining[3:])
326-
break
327-
}
328-
return l, fmt.Errorf("unexpected tail %s", remaining)
329-
}
330-
_, _ = sb.WriteRune(rn)
331-
remaining = tail
332-
}
333-
} else {
334-
idx := bytes.IndexByte(wr.tmp, ':')
335-
if idx < 0 {
336-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
337-
}
338-
working.Filename = string(wr.tmp[:idx])
339-
if len(wr.tmp) < idx+2 {
340-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
341-
}
342-
wr.tmp = wr.tmp[idx+2:]
343-
}
344-
345-
idx := bytes.IndexByte(wr.tmp, ':')
346-
if idx < 0 {
347-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
348-
}
349-
350-
working.Attribute = string(wr.tmp[:idx])
351-
if len(wr.tmp) < idx+2 {
352-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
353-
}
354-
355-
working.Value = string(wr.tmp[idx+2:])
356-
357-
wr.attributes <- working
358-
wr.tmp = wr.tmp[:0]
359-
if len(p) > nlIdx+1 {
360-
p = p[nlIdx+1:]
361-
nlIdx = bytes.IndexByte(p, '\n')
362-
continue
363-
} else {
364-
return l, nil
365-
}
366-
}
367-
368-
wr.tmp = append(wr.tmp, p...)
369-
return l, nil
370-
}
371-
372-
func (wr *lineSeparatedAttributeWriter) ReadAttribute() <-chan attributeTriple {
373-
return wr.attributes
374-
}
375-
376-
func (wr *lineSeparatedAttributeWriter) Close() error {
377-
select {
378-
case <-wr.closed:
379-
return nil
380-
default:
381-
}
382-
close(wr.attributes)
383-
close(wr.closed)
384-
return nil
385-
}
386-
387289
// Create a check attribute reader for the current repository and provided commit ID
388290
func (repo *Repository) CheckAttributeReader(commitID string) (*CheckAttributeReader, context.CancelFunc) {
389291
indexFilename, worktree, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)

modules/git/repo_attribute_test.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -95,64 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
9595
Value: "unspecified",
9696
}, attr)
9797
}
98-
99-
func Test_lineSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
100-
wr := &lineSeparatedAttributeWriter{
101-
attributes: make(chan attributeTriple, 5),
102-
}
103-
104-
testStr := `".gitignore\"\n": linguist-vendored: unspecified
105-
`
106-
n, err := wr.Write([]byte(testStr))
107-
108-
assert.Equal(t, n, len(testStr))
109-
assert.NoError(t, err)
110-
111-
select {
112-
case attr := <-wr.ReadAttribute():
113-
assert.Equal(t, ".gitignore\"\n", attr.Filename)
114-
assert.Equal(t, "linguist-vendored", attr.Attribute)
115-
assert.Equal(t, "unspecified", attr.Value)
116-
case <-time.After(100 * time.Millisecond):
117-
assert.Fail(t, "took too long to read an attribute from the list")
118-
}
119-
120-
// Write a second attribute again
121-
n, err = wr.Write([]byte(testStr))
122-
123-
assert.Equal(t, n, len(testStr))
124-
assert.NoError(t, err)
125-
126-
select {
127-
case attr := <-wr.ReadAttribute():
128-
assert.Equal(t, ".gitignore\"\n", attr.Filename)
129-
assert.Equal(t, "linguist-vendored", attr.Attribute)
130-
assert.Equal(t, "unspecified", attr.Value)
131-
case <-time.After(100 * time.Millisecond):
132-
assert.Fail(t, "took too long to read an attribute from the list")
133-
}
134-
135-
// Write a partial attribute
136-
_, err = wr.Write([]byte("incomplete-file"))
137-
assert.NoError(t, err)
138-
_, err = wr.Write([]byte("name: "))
139-
assert.NoError(t, err)
140-
select {
141-
case <-wr.ReadAttribute():
142-
assert.Fail(t, "There should not be an attribute ready to read")
143-
case <-time.After(100 * time.Millisecond):
144-
}
145-
_, err = wr.Write([]byte("attribute: "))
146-
assert.NoError(t, err)
147-
select {
148-
case <-wr.ReadAttribute():
149-
assert.Fail(t, "There should not be an attribute ready to read")
150-
case <-time.After(100 * time.Millisecond):
151-
}
152-
_, err = wr.Write([]byte("value\n"))
153-
assert.NoError(t, err)
154-
attr := <-wr.ReadAttribute()
155-
assert.Equal(t, "incomplete-filename", attr.Filename)
156-
assert.Equal(t, "attribute", attr.Attribute)
157-
assert.Equal(t, "value", attr.Value)
158-
}

modules/git/repo_commit_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (repo *Repository) RemoveReference(name string) error {
4141

4242
// ConvertToSHA1 returns a Hash object from a potential ID string
4343
func (repo *Repository) ConvertToSHA1(commitID string) (SHA1, error) {
44-
if len(commitID) == 40 {
44+
if len(commitID) == SHAFullLength {
4545
sha1, err := NewIDFromString(commitID)
4646
if err == nil {
4747
return sha1, nil

modules/git/repo_commit_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
137137

138138
// ConvertToSHA1 returns a Hash object from a potential ID string
139139
func (repo *Repository) ConvertToSHA1(commitID string) (SHA1, error) {
140-
if len(commitID) == 40 && IsValidSHAPattern(commitID) {
140+
if len(commitID) == SHAFullLength && IsValidSHAPattern(commitID) {
141141
sha1, err := NewIDFromString(commitID)
142142
if err == nil {
143143
return sha1, nil

modules/git/repo_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
// ReadTreeToIndex reads a treeish to the index
1818
func (repo *Repository) ReadTreeToIndex(treeish string, indexFilename ...string) error {
19-
if len(treeish) != 40 {
19+
if len(treeish) != SHAFullLength {
2020
res, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify").AddDynamicArguments(treeish).RunStdString(&RunOpts{Dir: repo.Path})
2121
if err != nil {
2222
return err

modules/git/repo_tree_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
1919

2020
// GetTree find the tree object in the repository.
2121
func (repo *Repository) GetTree(idStr string) (*Tree, error) {
22-
if len(idStr) != 40 {
22+
if len(idStr) != SHAFullLength {
2323
res, _, err := NewCommand(repo.Ctx, "rev-parse", "--verify").AddDynamicArguments(idStr).RunStdString(&RunOpts{Dir: repo.Path})
2424
if err != nil {
2525
return nil, err

modules/git/repo_tree_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
6666

6767
// GetTree find the tree object in the repository.
6868
func (repo *Repository) GetTree(idStr string) (*Tree, error) {
69-
if len(idStr) != 40 {
69+
if len(idStr) != SHAFullLength {
7070
res, err := repo.GetRefCommitID(idStr)
7171
if err != nil {
7272
return nil, err

0 commit comments

Comments
 (0)