Skip to content

Commit 0a5988a

Browse files
authored
Merge branch 'master' into slight-performance-improvement-for-last-commit-cache
2 parents deef959 + a67861b commit 0a5988a

File tree

14 files changed

+171
-105
lines changed

14 files changed

+171
-105
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ insert_final_newline = false
1818
[templates/swagger/v1_json.tmpl]
1919
indent_style = space
2020

21+
[templates/user/auth/oidc_wellknown.tmpl]
22+
indent_style = space
23+
2124
[Makefile]
2225
indent_style = tab
2326

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ _testmain.go
3232

3333
*coverage.out
3434
coverage.all
35+
cpu.out
3536

3637
/modules/options/bindata.go
3738
/modules/options/bindata.go.hash

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ This changelog goes through all the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.io).
66

7+
## [1.14.1](https://github.com/go-gitea/gitea/releases/tag/v1.14.1) - 2021-04-15
8+
9+
* BUGFIXES
10+
* Fix bug clone wiki (#15499) (#15502)
11+
* Github Migration ignore rate limit, if not enabled (#15490) (#15495)
12+
* Use subdir for URL (#15446) (#15493)
13+
* Query the DB for the hash before inserting in to email_hash (#15457) (#15491)
14+
* Ensure review dismissal only dismisses the correct review (#15477) (#15489)
15+
* Use index of the supported tags to choose user lang (#15452) (#15488)
16+
* Fix wrong file link in code search page (#15466) (#15486)
17+
* Quick template fix for built-in SSH server in admin config (#15464) (#15481)
18+
* Prevent superfluous response.WriteHeader (#15456) (#15476)
19+
* Fix ambiguous argument error on tags (#15432) (#15474)
20+
* Add created_unix instead of expiry to migration (#15458) (#15463)
21+
* Fix repository search (#15428) (#15442)
22+
* Prevent NPE on avatar direct rendering if federated avatars disabled (#15434) (#15439)
23+
* Fix wiki clone urls (#15430) (#15431)
24+
* Fix dingtalk icon url at webhook (#15417) (#15426)
25+
* Standardise icon on projects PR page (#15387) (#15408)
26+
* ENHANCEMENTS
27+
* Add option to skip LFS/attachment files for `dump` (#15407) (#15492)
28+
* Clone panel fixes (#15436)
29+
* Use semantic dropdown for code search query type (#15276) (#15364)
30+
* BUILD
31+
* Build go-git variants for windows (#15482) (#15487)
32+
* Lock down build-images dependencies (Partial #15479) (#15480)
33+
* MISC
34+
* Performance improvement for list pull requests (#15447) (#15500)
35+
* Fix potential copy lfs records failure when fork a repository (#15441) (#15485)
36+
737
## [1.14.0](https://github.com/go-gitea/gitea/releases/tag/v1.14.0) - 2021-04-11
838

939
* SECURITY

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.14.0
21+
version: 1.14.1
2222
minGoVersion: 1.14
2323
goVersion: 1.16
2424
minNodeVersion: 12.17

integrations/api_branch_test.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,28 @@ func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
151151
for _, test := range tests {
152152
defer resetFixtures(t)
153153
session := ctx.Session
154-
token := getTokenForLoggedInUser(t, session)
155-
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/my-noo-repo/branches?token="+token, &api.CreateBranchRepoOption{
156-
BranchName: test.NewBranch,
157-
OldBranchName: test.OldBranch,
158-
})
159-
resp := session.MakeRequest(t, req, test.ExpectedHTTPStatus)
160-
161-
var branch api.Branch
162-
DecodeJSON(t, resp, &branch)
163-
164-
if test.ExpectedHTTPStatus == http.StatusCreated {
165-
assert.EqualValues(t, test.NewBranch, branch.Name)
166-
}
154+
testAPICreateBranch(t, session, "user2", "my-noo-repo", test.OldBranch, test.NewBranch, test.ExpectedHTTPStatus)
167155
}
168156
}
169157

158+
func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBranch, newBranch string, status int) bool {
159+
token := getTokenForLoggedInUser(t, session)
160+
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+repo+"/branches?token="+token, &api.CreateBranchRepoOption{
161+
BranchName: newBranch,
162+
OldBranchName: oldBranch,
163+
})
164+
resp := session.MakeRequest(t, req, status)
165+
166+
var branch api.Branch
167+
DecodeJSON(t, resp, &branch)
168+
169+
if status == http.StatusCreated {
170+
assert.EqualValues(t, newBranch, branch.Name)
171+
}
172+
173+
return resp.Result().StatusCode == status
174+
}
175+
170176
func TestAPIBranchProtection(t *testing.T) {
171177
defer prepareTestEnv(t)()
172178

integrations/api_repo_file_create_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,36 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
105105
}
106106
}
107107

108+
func BenchmarkAPICreateFileSmall(b *testing.B) {
109+
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
110+
b := t.(*testing.B)
111+
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
112+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
113+
114+
for n := 0; n < b.N; n++ {
115+
treePath := fmt.Sprintf("update/file%d.txt", n)
116+
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
117+
}
118+
})
119+
}
120+
121+
func BenchmarkAPICreateFileMedium(b *testing.B) {
122+
data := make([]byte, 10*1024*1024)
123+
124+
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
125+
b := t.(*testing.B)
126+
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
127+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
128+
129+
b.ResetTimer()
130+
for n := 0; n < b.N; n++ {
131+
treePath := fmt.Sprintf("update/file%d.txt", n)
132+
copy(data, treePath)
133+
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
134+
}
135+
})
136+
}
137+
108138
func TestAPICreateFile(t *testing.T) {
109139
onGiteaRun(t, func(t *testing.T, u *url.URL) {
110140
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16

integrations/api_repo_file_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
api "code.gitea.io/gitea/modules/structs"
1111
)
1212

13-
func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName string) (*api.FileResponse, error) {
13+
func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
1414
opts := &repofiles.UpdateRepoFileOptions{
1515
OldBranch: branchName,
1616
TreePath: treePath,
17-
Content: "This is a NEW file",
17+
Content: content,
1818
IsNewFile: true,
1919
Author: nil,
2020
Committer: nil,
@@ -23,5 +23,5 @@ func createFileInBranch(user *models.User, repo *models.Repository, treePath, br
2323
}
2424

2525
func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
26-
return createFileInBranch(user, repo, treePath, repo.DefaultBranch)
26+
return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
2727
}

integrations/benchmarks_test.go

Lines changed: 40 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,14 @@ package integrations
77
import (
88
"math/rand"
99
"net/http"
10+
"net/url"
1011
"testing"
1112

1213
"code.gitea.io/gitea/models"
1314
api "code.gitea.io/gitea/modules/structs"
1415
)
1516

16-
func BenchmarkRepo(b *testing.B) {
17-
samples := []struct {
18-
url string
19-
name string
20-
skipShort bool
21-
}{
22-
{url: "https://github.com/go-gitea/gitea.git", name: "gitea"},
23-
{url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"},
24-
{url: "https://github.com/moby/moby.git", name: "moby", skipShort: true},
25-
{url: "https://github.com/golang/go.git", name: "go", skipShort: true},
26-
{url: "https://github.com/torvalds/linux.git", name: "linux", skipShort: true},
27-
}
28-
defer prepareTestEnv(b)()
29-
session := loginUser(b, "user2")
30-
b.ResetTimer()
31-
32-
for _, s := range samples {
33-
b.Run(s.name, func(b *testing.B) {
34-
if testing.Short() && s.skipShort {
35-
b.Skip("skipping test in short mode.")
36-
}
37-
b.Run("Migrate", func(b *testing.B) {
38-
for i := 0; i < b.N; i++ {
39-
testRepoMigrate(b, session, s.url, s.name)
40-
}
41-
})
42-
b.Run("Access", func(b *testing.B) {
43-
var branches []*api.Branch
44-
b.Run("APIBranchList", func(b *testing.B) {
45-
for i := 0; i < b.N; i++ {
46-
req := NewRequestf(b, "GET", "/api/v1/repos/%s/%s/branches", "user2", s.name)
47-
resp := session.MakeRequest(b, req, http.StatusOK)
48-
b.StopTimer()
49-
if len(branches) == 0 {
50-
DecodeJSON(b, resp, &branches) //Store for next phase
51-
}
52-
b.StartTimer()
53-
}
54-
})
55-
branchCount := len(branches)
56-
b.Run("WebViewCommit", func(b *testing.B) {
57-
for i := 0; i < b.N; i++ {
58-
req := NewRequestf(b, "GET", "/%s/%s/commit/%s", "user2", s.name, branches[i%branchCount].Commit.ID)
59-
session.MakeRequest(b, req, http.StatusOK)
60-
}
61-
})
62-
})
63-
})
64-
}
65-
}
66-
67-
//StringWithCharset random string (from https://www.calhoun.io/creating-random-strings-in-go/)
17+
// StringWithCharset random string (from https://www.calhoun.io/creating-random-strings-in-go/)
6818
func StringWithCharset(length int, charset string) string {
6919
b := make([]byte, length)
7020
for i := range b {
@@ -74,40 +24,48 @@ func StringWithCharset(length int, charset string) string {
7424
}
7525

7626
func BenchmarkRepoBranchCommit(b *testing.B) {
77-
samples := []int64{1, 3, 15, 16}
78-
defer prepareTestEnv(b)()
79-
b.ResetTimer()
27+
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
28+
b := t.(*testing.B)
29+
30+
samples := []int64{1, 2, 3}
31+
b.ResetTimer()
8032

81-
for _, repoID := range samples {
82-
b.StopTimer()
83-
repo := models.AssertExistsAndLoadBean(b, &models.Repository{ID: repoID}).(*models.Repository)
84-
b.StartTimer()
85-
b.Run(repo.Name, func(b *testing.B) {
86-
owner := models.AssertExistsAndLoadBean(b, &models.User{ID: repo.OwnerID}).(*models.User)
87-
session := loginUser(b, owner.LoginName)
88-
b.ResetTimer()
89-
b.Run("Create", func(b *testing.B) {
90-
for i := 0; i < b.N; i++ {
33+
for _, repoID := range samples {
34+
b.StopTimer()
35+
repo := models.AssertExistsAndLoadBean(b, &models.Repository{ID: repoID}).(*models.Repository)
36+
b.StartTimer()
37+
b.Run(repo.Name, func(b *testing.B) {
38+
session := loginUser(b, "user2")
39+
b.ResetTimer()
40+
b.Run("CreateBranch", func(b *testing.B) {
9141
b.StopTimer()
9242
branchName := StringWithCharset(5+rand.Intn(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
9343
b.StartTimer()
94-
testCreateBranch(b, session, owner.LoginName, repo.Name, "branch/master", branchName, http.StatusFound)
95-
}
96-
})
97-
b.Run("Access", func(b *testing.B) {
98-
var branches []*api.Branch
99-
req := NewRequestf(b, "GET", "/api/v1/%s/branches", repo.FullName())
100-
resp := session.MakeRequest(b, req, http.StatusOK)
101-
DecodeJSON(b, resp, &branches)
102-
branchCount := len(branches)
103-
b.ResetTimer() //We measure from here
104-
for i := 0; i < b.N; i++ {
105-
req := NewRequestf(b, "GET", "/%s/%s/commits/%s", owner.Name, repo.Name, branches[i%branchCount].Name)
44+
for i := 0; i < b.N; i++ {
45+
b.Run("new_"+branchName, func(b *testing.B) {
46+
b.Skip("benchmark broken") // TODO fix
47+
testAPICreateBranch(b, session, repo.OwnerName, repo.Name, repo.DefaultBranch, "new_"+branchName, http.StatusCreated)
48+
})
49+
}
50+
})
51+
b.Run("GetBranches", func(b *testing.B) {
52+
req := NewRequestf(b, "GET", "/api/v1/repos/%s/branches", repo.FullName())
10653
session.MakeRequest(b, req, http.StatusOK)
107-
}
54+
})
55+
b.Run("AccessCommits", func(b *testing.B) {
56+
var branches []*api.Branch
57+
req := NewRequestf(b, "GET", "/api/v1/repos/%s/branches", repo.FullName())
58+
resp := session.MakeRequest(b, req, http.StatusOK)
59+
DecodeJSON(b, resp, &branches)
60+
b.ResetTimer() //We measure from here
61+
if len(branches) != 0 {
62+
for i := 0; i < b.N; i++ {
63+
req := NewRequestf(b, "GET", "/api/v1/repos/%s/commits?sha=%s", repo.FullName(), branches[i%len(branches)].Name)
64+
session.MakeRequest(b, req, http.StatusOK)
65+
}
66+
}
67+
})
10868
})
109-
})
110-
}
69+
}
70+
})
11171
}
112-
113-
//TODO list commits /repos/{owner}/{repo}/commits

integrations/git_helper_for_declarative_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func allowLFSFilters() []string {
7676
return filteredLFSGlobalArgs[:j]
7777
}
7878

79-
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
79+
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
8080
if len(prepare) == 0 || prepare[0] {
8181
defer prepareTestEnv(t, 1)()
8282
}
@@ -108,6 +108,12 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
108108
callback(t, u)
109109
}
110110

111+
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
112+
onGiteaRunTB(t, func(t testing.TB, u *url.URL) {
113+
callback(t.(*testing.T), u)
114+
}, prepare...)
115+
}
116+
111117
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
112118
return func(t *testing.T) {
113119
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{}))

routers/repo/http.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
103103

104104
isWiki := false
105105
var unitType = models.UnitTypeCode
106+
var wikiRepoName string
106107
if strings.HasSuffix(reponame, ".wiki") {
107108
isWiki = true
108109
unitType = models.UnitTypeWiki
110+
wikiRepoName = reponame
109111
reponame = reponame[:len(reponame)-5]
110112
}
111113

@@ -314,6 +316,11 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
314316
return
315317
}
316318

319+
if isWiki { // you cannot send wiki operation before create the repository
320+
ctx.HandleText(http.StatusNotFound, "Repository not found")
321+
return
322+
}
323+
317324
if owner.IsOrganization() && !setting.Repository.EnablePushCreateOrg {
318325
ctx.HandleText(http.StatusForbidden, "Push to create is not enabled for organizations.")
319326
return
@@ -363,6 +370,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
363370
r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name
364371

365372
dir := models.RepoPath(username, reponame)
373+
if isWiki {
374+
dir = models.RepoPath(username, wikiRepoName)
375+
}
366376

367377
return &serviceHandler{cfg, w, r, dir, cfg.Env}
368378
}

routers/routes/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ func RegisterRoutes(m *web.Route) {
336336
// Routers.
337337
// for health check
338338
m.Get("/", routers.Home)
339+
m.Get("/.well-known/openid-configuration", user.OIDCWellKnown)
339340
m.Group("/explore", func() {
340341
m.Get("", func(ctx *context.Context) {
341342
ctx.Redirect(setting.AppSubURL + "/explore/repos")

routers/user/oauth.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ func GrantApplicationOAuth(ctx *context.Context) {
389389
ctx.Redirect(redirect.String(), 302)
390390
}
391391

392+
// OIDCWellKnown generates JSON so OIDC clients know Gitea's capabilities
393+
func OIDCWellKnown(ctx *context.Context) {
394+
t := ctx.Render.TemplateLookup("user/auth/oidc_wellknown")
395+
ctx.Resp.Header().Set("Content-Type", "application/json")
396+
if err := t.Execute(ctx.Resp, ctx.Data); err != nil {
397+
log.Error("%v", err)
398+
ctx.Error(http.StatusInternalServerError)
399+
}
400+
}
401+
392402
// AccessTokenOAuth manages all access token requests by the client
393403
func AccessTokenOAuth(ctx *context.Context) {
394404
form := *web.GetForm(ctx).(*forms.AccessTokenForm)

0 commit comments

Comments
 (0)