Skip to content

Commit aece370

Browse files
authored
Merge branch 'master' into oauth2-auto-register
2 parents 8a64dfe + 240fea8 commit aece370

File tree

11 files changed

+152
-39
lines changed

11 files changed

+152
-39
lines changed

integrations/api_repo_git_commits_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
)
1616

17+
func compareCommitFiles(t *testing.T, expect []string, files []*api.CommitAffectedFiles) {
18+
var actual []string
19+
for i := range files {
20+
actual = append(actual, files[i].Filename)
21+
}
22+
assert.ElementsMatch(t, expect, actual)
23+
}
24+
1725
func TestAPIReposGitCommits(t *testing.T) {
1826
defer prepareTestEnv(t)()
1927
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
@@ -56,10 +64,13 @@ func TestAPIReposGitCommitList(t *testing.T) {
5664
var apiData []api.Commit
5765
DecodeJSON(t, resp, &apiData)
5866

59-
assert.Equal(t, 3, len(apiData))
60-
assert.Equal(t, "69554a64c1e6030f051e5c3f94bfbd773cd6a324", apiData[0].CommitMeta.SHA)
61-
assert.Equal(t, "27566bd5738fc8b4e3fef3c5e72cce608537bd95", apiData[1].CommitMeta.SHA)
62-
assert.Equal(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
67+
assert.Len(t, apiData, 3)
68+
assert.EqualValues(t, "69554a64c1e6030f051e5c3f94bfbd773cd6a324", apiData[0].CommitMeta.SHA)
69+
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
70+
assert.EqualValues(t, "27566bd5738fc8b4e3fef3c5e72cce608537bd95", apiData[1].CommitMeta.SHA)
71+
compareCommitFiles(t, []string{"readme.md"}, apiData[1].Files)
72+
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
73+
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
6374
}
6475

6576
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
@@ -76,7 +87,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
7687
var apiData []api.Commit
7788
DecodeJSON(t, resp, &apiData)
7889

79-
assert.Equal(t, 0, len(apiData))
90+
assert.Len(t, apiData, 0)
8091
}
8192

8293
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
@@ -93,6 +104,7 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
93104
var apiData []api.Commit
94105
DecodeJSON(t, resp, &apiData)
95106

96-
assert.Equal(t, 1, len(apiData))
107+
assert.Len(t, apiData, 1)
97108
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
109+
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
98110
}

modules/convert/git_commit.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
131131
}
132132
}
133133

134+
// Retrieve files affected by the commit
135+
fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String())
136+
if err != nil {
137+
return nil, err
138+
}
139+
affectedFileList := make([]*api.CommitAffectedFiles, 0, len(fileStatus.Added)+len(fileStatus.Removed)+len(fileStatus.Modified))
140+
for _, files := range [][]string{fileStatus.Added, fileStatus.Removed, fileStatus.Modified} {
141+
for _, filename := range files {
142+
affectedFileList = append(affectedFileList, &api.CommitAffectedFiles{
143+
Filename: filename,
144+
})
145+
}
146+
}
147+
134148
return &api.Commit{
135149
CommitMeta: &api.CommitMeta{
136150
URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
@@ -162,5 +176,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
162176
Author: apiAuthor,
163177
Committer: apiCommitter,
164178
Parents: apiParents,
179+
Files: affectedFileList,
165180
}, nil
166181
}

modules/migrations/github.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,15 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
301301
Created: asset.CreatedAt.Time,
302302
Updated: asset.UpdatedAt.Time,
303303
DownloadFunc: func() (io.ReadCloser, error) {
304+
g.sleep()
304305
asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, *asset.ID, http.DefaultClient)
305306
if err != nil {
306307
return nil, err
307308
}
309+
err = g.RefreshRate()
310+
if err != nil {
311+
log.Error("g.client.RateLimits: %s", err)
312+
}
308313
if asset == nil {
309314
return ioutil.NopCloser(bytes.NewBufferString(redir)), nil
310315
}

modules/structs/repo_commit.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ type RepoCommit struct {
4242
// Commit contains information generated from a Git commit.
4343
type Commit struct {
4444
*CommitMeta
45-
HTMLURL string `json:"html_url"`
46-
RepoCommit *RepoCommit `json:"commit"`
47-
Author *User `json:"author"`
48-
Committer *User `json:"committer"`
49-
Parents []*CommitMeta `json:"parents"`
45+
HTMLURL string `json:"html_url"`
46+
RepoCommit *RepoCommit `json:"commit"`
47+
Author *User `json:"author"`
48+
Committer *User `json:"committer"`
49+
Parents []*CommitMeta `json:"parents"`
50+
Files []*CommitAffectedFiles `json:"files"`
5051
}
5152

5253
// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
@@ -56,3 +57,8 @@ type CommitDateOptions struct {
5657
// swagger:strfmt date-time
5758
Committer time.Time `json:"committer"`
5859
}
60+
61+
// CommitAffectedFiles store information about files affected by the commit
62+
type CommitAffectedFiles struct {
63+
Filename string `json:"filename"`
64+
}

modules/translation/translation.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package translation
66

77
import (
8+
"errors"
9+
810
"code.gitea.io/gitea/modules/log"
911
"code.gitea.io/gitea/modules/options"
1012
"code.gitea.io/gitea/modules/setting"
@@ -57,8 +59,13 @@ func InitLocales() {
5759
matcher = language.NewMatcher(tags)
5860
for i := range setting.Names {
5961
key := "locale_" + setting.Langs[i] + ".ini"
60-
if err := i18n.SetMessageWithDesc(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
61-
log.Fatal("Failed to set messages to %s: %v", setting.Langs[i], err)
62+
if err = i18n.SetMessageWithDesc(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
63+
if errors.Is(err, i18n.ErrLangAlreadyExist) {
64+
// just log if lang is already loaded since we can not reload it
65+
log.Warn("Can not load language '%s' since already loaded", setting.Langs[i])
66+
} else {
67+
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
68+
}
6269
}
6370
}
6471
i18n.SetDefaultLang("en-US")

options/license/FreeBSD-DOC

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
The FreeBSD Documentation License
2+
3+
Copyright 1994-2021 The FreeBSD Project. All rights reserved.
4+
5+
Redistribution and use in source (SGML DocBook) and 'compiled' forms (SGML,
6+
HTML, PDF, PostScript, RTF and so forth) with or without modification, are
7+
permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code (SGML DocBook) must retain the above copyright
10+
notice, this list of conditions and the following disclaimer as the first
11+
lines of this file unmodified.
12+
13+
2. Redistributions in compiled form (transformed to other DTDs, converted
14+
to PDF, PostScript, RTF and other formats) must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
THIS DOCUMENTATION IS PROVIDED BY THE FREEBSD DOCUMENTATION PROJECT "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD DOCUMENTATION PROJECT BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27+
USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
Manual Pages
30+
31+
Some FreeBSD manual pages contain text from the IEEE Std 1003.1, 2004 Edition,
32+
Standard for Information Technology — Portable Operating System Interface
33+
(POSIX®) specification. These manual pages are subject to the following terms:
34+
35+
The Institute of Electrical and Electronics Engineers and The Open Group,
36+
have given us permission to reprint portions of their documentation.
37+
38+
In the following statement, the phrase "this text" refers to portions of the
39+
system documentation.
40+
41+
Portions of this text are reprinted and reproduced in electronic form in the
42+
FreeBSD manual pages, from IEEE Std 1003.1, 2004 Edition, Standard for Information
43+
Technology — Portable Operating System Interface (POSIX), The Open Group Base
44+
Specifications Issue 6, Copyright© 2001-2004 by the Institute of Electrical
45+
and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy
46+
between these versions and the original IEEE and The Open Group Standard,
47+
the original IEEE and The Open Group Standard is the referee document. The
48+
original Standard can be obtained online at https://www.opengroup.org/membership/forums/platform/unix.
49+
50+
This notice shall appear on any product containing this material.

routers/repo/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func GetAttachment(ctx *context.Context) {
152152
return
153153
}
154154

155-
if err = ServeData(ctx, attach.Name, fr); err != nil {
155+
if err = ServeData(ctx, attach.Name, attach.Size, fr); err != nil {
156156
ctx.ServerError("ServeData", err)
157157
return
158158
}

routers/repo/download.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
// ServeData download file from io.Reader
23-
func ServeData(ctx *context.Context, name string, reader io.Reader) error {
23+
func ServeData(ctx *context.Context, name string, size int64, reader io.Reader) error {
2424
buf := make([]byte, 1024)
2525
n, err := reader.Read(buf)
2626
if err != nil && err != io.EOF {
@@ -31,6 +31,11 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
3131
}
3232

3333
ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400")
34+
if size >= 0 {
35+
ctx.Resp.Header().Set("Content-Length", fmt.Sprintf("%d", size))
36+
} else {
37+
log.Error("ServeData called to serve data: %s with size < 0: %d", name, size)
38+
}
3439
name = path.Base(name)
3540

3641
// Google Chrome dislike commas in filenames, so let's change it to a space
@@ -76,7 +81,7 @@ func ServeBlob(ctx *context.Context, blob *git.Blob) error {
7681
}
7782
}()
7883

79-
return ServeData(ctx, ctx.Repo.TreePath, dataRc)
84+
return ServeData(ctx, ctx.Repo.TreePath, blob.Size(), dataRc)
8085
}
8186

8287
// ServeBlobOrLFS download a git.Blob redirecting to LFS if necessary
@@ -105,7 +110,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error {
105110
log.Error("ServeBlobOrLFS: Close: %v", err)
106111
}
107112
}()
108-
return ServeData(ctx, ctx.Repo.TreePath, lfsDataRc)
113+
return ServeData(ctx, ctx.Repo.TreePath, meta.Size, lfsDataRc)
109114
}
110115

111116
return ServeBlob(ctx, blob)

routers/repo/view.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
385385

386386
fileSize := blob.Size()
387387
ctx.Data["FileIsSymlink"] = entry.IsLink()
388-
ctx.Data["FileSize"] = fileSize
389388
ctx.Data["FileName"] = blob.Name()
390389
ctx.Data["RawFileLink"] = rawLink + "/" + ctx.Repo.TreePath
391390

@@ -395,21 +394,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
395394

396395
isTextFile := base.IsTextFile(buf)
397396
isLFSFile := false
398-
ctx.Data["IsTextFile"] = isTextFile
399-
400397
isDisplayingSource := ctx.Query("display") == "source"
401398
isDisplayingRendered := !isDisplayingSource
402-
isRepresentableAsText := base.IsRepresentableAsText(buf)
403-
ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
404-
if !isRepresentableAsText {
405-
// If we can't show plain text, always try to render.
406-
isDisplayingSource = false
407-
isDisplayingRendered = true
408-
}
409-
ctx.Data["IsDisplayingSource"] = isDisplayingSource
410-
ctx.Data["IsDisplayingRendered"] = isDisplayingRendered
411-
412-
ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource
413399

414400
//Check for LFS meta file
415401
if isTextFile && setting.LFS.StartServer {
@@ -422,7 +408,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
422408
}
423409
}
424410
if meta != nil {
425-
ctx.Data["IsLFSFile"] = true
426411
isLFSFile = true
427412

428413
// OK read the lfs object
@@ -445,14 +430,25 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
445430
buf = buf[:n]
446431

447432
isTextFile = base.IsTextFile(buf)
448-
ctx.Data["IsTextFile"] = isTextFile
449-
450433
fileSize = meta.Size
451-
ctx.Data["FileSize"] = meta.Size
452-
filenameBase64 := base64.RawURLEncoding.EncodeToString([]byte(blob.Name()))
453-
ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
434+
ctx.Data["RawFileLink"] = fmt.Sprintf("%s/media/%s/%s", ctx.Repo.RepoLink, ctx.Repo.BranchNameSubURL(), ctx.Repo.TreePath)
454435
}
455436
}
437+
438+
isRepresentableAsText := base.IsRepresentableAsText(buf)
439+
if !isRepresentableAsText {
440+
// If we can't show plain text, always try to render.
441+
isDisplayingSource = false
442+
isDisplayingRendered = true
443+
}
444+
ctx.Data["IsLFSFile"] = isLFSFile
445+
ctx.Data["FileSize"] = fileSize
446+
ctx.Data["IsTextFile"] = isTextFile
447+
ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
448+
ctx.Data["IsDisplayingSource"] = isDisplayingSource
449+
ctx.Data["IsDisplayingRendered"] = isDisplayingRendered
450+
ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource
451+
456452
// Check LFS Lock
457453
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
458454
ctx.Data["LFSLock"] = lfsLock
@@ -542,7 +538,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
542538
ctx.Data["MarkupType"] = markupType
543539
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeDocumentMetas()))
544540
}
545-
546541
}
547542

548543
if ctx.Repo.CanEnableEditor() {

routers/user/auth_openid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
412412
Name: form.UserName,
413413
Email: form.Email,
414414
Passwd: password,
415-
IsActive: !setting.Service.RegisterEmailConfirm,
415+
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
416416
}
417417
if !createUserInContext(ctx, tplSignUpOID, form, u) {
418418
// error already handled

templates/swagger/v1_json.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11821,6 +11821,13 @@
1182111821
"format": "date-time",
1182211822
"x-go-name": "Created"
1182311823
},
11824+
"files": {
11825+
"type": "array",
11826+
"items": {
11827+
"$ref": "#/definitions/CommitAffectedFiles"
11828+
},
11829+
"x-go-name": "Files"
11830+
},
1182411831
"html_url": {
1182511832
"type": "string",
1182611833
"x-go-name": "HTMLURL"
@@ -11843,6 +11850,17 @@
1184311850
},
1184411851
"x-go-package": "code.gitea.io/gitea/modules/structs"
1184511852
},
11853+
"CommitAffectedFiles": {
11854+
"description": "CommitAffectedFiles store information about files affected by the commit",
11855+
"type": "object",
11856+
"properties": {
11857+
"filename": {
11858+
"type": "string",
11859+
"x-go-name": "Filename"
11860+
}
11861+
},
11862+
"x-go-package": "code.gitea.io/gitea/modules/structs"
11863+
},
1184611864
"CommitDateOptions": {
1184711865
"description": "CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE",
1184811866
"type": "object",

0 commit comments

Comments
 (0)