Skip to content

Commit 177e3ac

Browse files
committed
Merge remote-tracking branch 'go-gitea/main' into issue-content-history
2 parents 7952ccf + ded438f commit 177e3ac

File tree

14 files changed

+159
-53
lines changed

14 files changed

+159
-53
lines changed

cmd/doctor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func runRecreateTable(ctx *cli.Context) error {
124124
}
125125

126126
func runDoctor(ctx *cli.Context) error {
127-
128127
// Silence the default loggers
129128
log.DelNamedLogger("console")
130129
log.DelNamedLogger(log.DEFAULT)

models/attachment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ func GetAttachmentByUUID(uuid string) (*Attachment, error) {
144144
return getAttachmentByUUID(x, uuid)
145145
}
146146

147+
// ExistAttachmentsByUUID returns true if attachment is exist by given UUID
148+
func ExistAttachmentsByUUID(uuid string) (bool, error) {
149+
return x.Where("`uuid`=?", uuid).Exist(new(Attachment))
150+
}
151+
147152
// GetAttachmentByReleaseIDFileName returns attachment by given releaseId and fileName.
148153
func GetAttachmentByReleaseIDFileName(releaseID int64, fileName string) (*Attachment, error) {
149154
return getAttachmentByReleaseIDFileName(x, releaseID, fileName)

modules/doctor/storage.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package doctor
6+
7+
import (
8+
"code.gitea.io/gitea/models"
9+
"code.gitea.io/gitea/modules/log"
10+
"code.gitea.io/gitea/modules/storage"
11+
)
12+
13+
func checkAttachmentStorageFiles(logger log.Logger, autofix bool) error {
14+
var total, garbageNum int
15+
var deletePaths []string
16+
if err := storage.Attachments.IterateObjects(func(p string, obj storage.Object) error {
17+
defer obj.Close()
18+
19+
total++
20+
stat, err := obj.Stat()
21+
if err != nil {
22+
return err
23+
}
24+
exist, err := models.ExistAttachmentsByUUID(stat.Name())
25+
if err != nil {
26+
return err
27+
}
28+
if !exist {
29+
garbageNum++
30+
if autofix {
31+
deletePaths = append(deletePaths, p)
32+
}
33+
}
34+
return nil
35+
}); err != nil {
36+
logger.Error("storage.Attachments.IterateObjects failed: %v", err)
37+
return err
38+
}
39+
40+
if garbageNum > 0 {
41+
if autofix {
42+
var deletedNum int
43+
for _, p := range deletePaths {
44+
if err := storage.Attachments.Delete(p); err != nil {
45+
log.Error("Delete attachment %s failed: %v", p, err)
46+
} else {
47+
deletedNum++
48+
}
49+
}
50+
logger.Info("%d missed information attachment detected, %d deleted.", garbageNum, deletedNum)
51+
} else {
52+
logger.Warn("Checked %d attachment, %d missed information.", total, garbageNum)
53+
}
54+
}
55+
return nil
56+
}
57+
58+
func checkStorageFiles(logger log.Logger, autofix bool) error {
59+
if err := storage.Init(); err != nil {
60+
logger.Error("storage.Init failed: %v", err)
61+
return err
62+
}
63+
return checkAttachmentStorageFiles(logger, autofix)
64+
}
65+
66+
func init() {
67+
Register(&Check{
68+
Title: "Check if there is garbage storage files",
69+
Name: "storages",
70+
IsDefault: false,
71+
Run: checkStorageFiles,
72+
AbortIfFailed: false,
73+
SkipDatabaseInitialization: false,
74+
Priority: 1,
75+
})
76+
}

modules/migrations/gitea_downloader.go

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -459,49 +459,48 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
459459
func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
460460
var allComments = make([]*base.Comment, 0, g.maxPerPage)
461461

462-
// for i := 1; ; i++ {
463-
// make sure gitea can shutdown gracefully
464-
select {
465-
case <-g.ctx.Done():
466-
return nil, false, nil
467-
default:
468-
}
469-
470-
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
471-
// PageSize: g.maxPerPage,
472-
// Page: i,
473-
}})
474-
if err != nil {
475-
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err)
476-
}
462+
for i := 1; ; i++ {
463+
// make sure gitea can shutdown gracefully
464+
select {
465+
case <-g.ctx.Done():
466+
return nil, false, nil
467+
default:
468+
}
477469

478-
for _, comment := range comments {
479-
reactions, err := g.getCommentReactions(comment.ID)
470+
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
471+
PageSize: g.maxPerPage,
472+
Page: i,
473+
}})
480474
if err != nil {
481-
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)
482-
if err2 := models.CreateRepositoryNotice(
483-
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
484-
log.Error("create repository notice failed: ", err2)
475+
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err)
476+
}
477+
478+
for _, comment := range comments {
479+
reactions, err := g.getCommentReactions(comment.ID)
480+
if err != nil {
481+
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)
482+
if err2 := models.CreateRepositoryNotice(
483+
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
484+
log.Error("create repository notice failed: ", err2)
485+
}
485486
}
487+
488+
allComments = append(allComments, &base.Comment{
489+
IssueIndex: opts.Context.LocalID(),
490+
PosterID: comment.Poster.ID,
491+
PosterName: comment.Poster.UserName,
492+
PosterEmail: comment.Poster.Email,
493+
Content: comment.Body,
494+
Created: comment.Created,
495+
Updated: comment.Updated,
496+
Reactions: reactions,
497+
})
486498
}
487499

488-
allComments = append(allComments, &base.Comment{
489-
IssueIndex: opts.Context.LocalID(),
490-
PosterID: comment.Poster.ID,
491-
PosterName: comment.Poster.UserName,
492-
PosterEmail: comment.Poster.Email,
493-
Content: comment.Body,
494-
Created: comment.Created,
495-
Updated: comment.Updated,
496-
Reactions: reactions,
497-
})
500+
if !g.pagination || len(comments) < g.maxPerPage {
501+
break
502+
}
498503
}
499-
500-
// TODO enable pagination vor (gitea >= 1.14) when it got implemented
501-
// if !g.pagination || len(comments) < g.maxPerPage {
502-
// break
503-
// }
504-
//}
505504
return allComments, true, nil
506505
}
507506

modules/migrations/migrate.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,7 @@ func Init() error {
475475
return nil
476476
}
477477

478-
// isIPPrivate reports whether ip is a private address, according to
479-
// RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
480-
// from https://github.com/golang/go/pull/42793
481-
// TODO remove if https://github.com/golang/go/issues/29146 got resolved
478+
// TODO: replace with `ip.IsPrivate()` if min go version is bumped to 1.17
482479
func isIPPrivate(ip net.IP) bool {
483480
if ip4 := ip.To4(); ip4 != nil {
484481
return ip4[0] == 10 ||

modules/storage/minio.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type minioFileInfo struct {
151151
}
152152

153153
func (m minioFileInfo) Name() string {
154-
return m.ObjectInfo.Key
154+
return path.Base(m.ObjectInfo.Key)
155155
}
156156

157157
func (m minioFileInfo) Size() int64 {
@@ -219,7 +219,7 @@ func (m *MinioStorage) IterateObjects(fn func(path string, obj Object) error) er
219219
}
220220
if err := func(object *minio.Object, fn func(path string, obj Object) error) error {
221221
defer object.Close()
222-
return fn(strings.TrimPrefix(m.basePath, mObjInfo.Key), &minioObject{object})
222+
return fn(strings.TrimPrefix(mObjInfo.Key, m.basePath), &minioObject{object})
223223
}(object, fn); err != nil {
224224
return convertMinioErr(err)
225225
}

modules/templates/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ type Actioner interface {
777777
// ActionIcon accepts an action operation type and returns an icon class name.
778778
func ActionIcon(opType models.ActionType) string {
779779
switch opType {
780-
case models.ActionCreateRepo, models.ActionTransferRepo:
780+
case models.ActionCreateRepo, models.ActionTransferRepo, models.ActionRenameRepo:
781781
return "repo"
782782
case models.ActionCommitRepo, models.ActionPushTag, models.ActionDeleteTag, models.ActionDeleteBranch:
783783
return "git-commit"

options/locale/locale_el-GR.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ cancel=Ακύρωση
523523
language=Γλώσσα
524524
ui=Θέμα Διεπαφής
525525
privacy=Απόρρητο
526-
keep_activity_private=Απόκρυψη δραστηριότητας από τη σελίδα προφίλ
527-
keep_activity_private_popup=Κάνει τη δραστηριότητα ορατή μόνο για εσάς και τους διαχειριστές
526+
keep_activity_private=Απόκρυψη της δραστηριότητας σας από τη σελίδα προφίλ
527+
keep_activity_private_popup=Με αυτή την επιλογή η δραστηριότητα σας είναι ορατή μόνο σε εσάς και τους διαχειριστές
528528

529529
lookup_avatar_by_mail=Αναζήτηση ενός Avatar με διεύθυνση email
530530
federated_avatar_lookup=Συνενωμένη Αναζήτηση Avatar
@@ -2715,7 +2715,7 @@ notices.delete_success=Οι ειδοποιήσεις του συστήματος
27152715
[action]
27162716
create_repo=δημιούργησε το αποθετήριο <a href="%s">%s</a>
27172717
rename_repo=μετονόμασε το αποθετήριο από <code>%[1]s</code> σε <a href="%[2]s">%[3]s</a>
2718-
commit_repo=έκανε push στο <a href="%[1]s/src/branch/%[2]s">%[3]s</a> στις <a href="%[1]s">%[4]s</a>
2718+
commit_repo=έκανε push στο <a href="%[1]s/src/branch/%[2]s">%[3]s</a> του <a href="%[1]s">%[4]s</a>
27192719
create_issue=`άνοιξε το ζήτημα <a href="%s/issues/%s">%s#%[2]s</a>`
27202720
close_issue=`έκλεισε το ζήτημα <a href="%s/issues/%s">%s#%[2]s</a>`
27212721
reopen_issue=`άνοιξε ξανά το ζήτημα <a href="%s/issues/%s">%s#%[2]s</a>`
@@ -2740,7 +2740,7 @@ reject_pull_request=`πρότεινε αλλαγές για το <a href="%s/pul
27402740
publish_release=`έκδωσε τη <a href="%s/releases/tag/%s"> "%[4]s" </a> σε <a href="%[1]s">%[3]s</a>`
27412741
review_dismissed=`ακύρωσε την εξέταση από <b>%[4]s</b> for <a href="%[1]s/pulls/%[2]s">%[3]s#%[2]s</a>`
27422742
review_dismissed_reason=Αιτία:
2743-
create_branch=δημιούργησε το κλάδο <a href="%[1]s/src/branch/%[2]s">%[3]s</a> σε <a href="%[1]s">%[4]s</a>
2743+
create_branch=δημιούργησε το κλάδο <a href="%[1]s/src/branch/%[2]s">%[3]s</a> στο <a href="%[1]s">%[4]s</a>
27442744
27452745
[tool]
27462746
ago=%s πριν

options/locale/locale_ja-JP.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,8 @@ pulls.status_checks_failure=失敗したステータスチェックがありま
14681468
pulls.status_checks_error=ステータスチェックによりエラーが出ています
14691469
pulls.status_checks_requested=必須
14701470
pulls.status_checks_details=詳細
1471+
pulls.update_branch=マージでブランチを更新
1472+
pulls.update_branch_rebase=リベースでブランチを更新
14711473
pulls.update_branch_success=ブランチの更新が成功しました
14721474
pulls.update_not_allowed=ブランチを更新する権限がありません
14731475
pulls.outdated_with_base_branch=このブランチはベースブランチに対して最新ではありません

routers/api/v1/repo/pull.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ func UpdatePullRequest(ctx *context.APIContext) {
11361136
if models.IsErrMergeConflicts(err) {
11371137
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
11381138
return
1139+
} else if models.IsErrRebaseConflicts(err) {
1140+
ctx.Error(http.StatusConflict, "Update", "rebase failed because of conflict")
1141+
return
11391142
}
11401143
ctx.Error(http.StatusInternalServerError, "pull_service.Update", err)
11411144
return

routers/web/repo/pull.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,21 @@ func UpdatePullRequest(ctx *context.Context) {
766766
ctx.Flash.Error(flashError)
767767
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
768768
return
769+
} else if models.IsErrRebaseConflicts(err) {
770+
conflictError := err.(models.ErrRebaseConflicts)
771+
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
772+
"Message": ctx.Tr("repo.pulls.rebase_conflict", utils.SanitizeFlashErrorString(conflictError.CommitSHA)),
773+
"Summary": ctx.Tr("repo.pulls.rebase_conflict_summary"),
774+
"Details": utils.SanitizeFlashErrorString(conflictError.StdErr) + "<br>" + utils.SanitizeFlashErrorString(conflictError.StdOut),
775+
})
776+
if err != nil {
777+
ctx.ServerError("UpdatePullRequest.HTMLString", err)
778+
return
779+
}
780+
ctx.Flash.Error(flashError)
781+
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))
782+
return
783+
769784
}
770785
ctx.Flash.Error(err.Error())
771786
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index))

routers/web/user/avatar.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ import (
1313

1414
"code.gitea.io/gitea/models"
1515
"code.gitea.io/gitea/modules/context"
16+
"code.gitea.io/gitea/modules/httpcache"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
1819
)
1920

21+
func cacheableRedirect(ctx *context.Context, location string) {
22+
ctx.Resp.Header().Set("Cache-Control", httpcache.GetCacheControl())
23+
ctx.Redirect(location)
24+
}
25+
2026
// Avatar redirect browser to user avatar of requested size
2127
func Avatar(ctx *context.Context) {
2228
userName := ctx.Params(":username")
@@ -43,7 +49,7 @@ func Avatar(ctx *context.Context) {
4349
user = models.NewGhostUser()
4450
}
4551

46-
ctx.Redirect(user.RealSizedAvatarLink(size))
52+
cacheableRedirect(ctx, user.RealSizedAvatarLink(size))
4753
}
4854

4955
// AvatarByEmailHash redirects the browser to the appropriate Avatar link
@@ -63,7 +69,7 @@ func AvatarByEmailHash(ctx *context.Context) {
6369
return
6470
}
6571
if len(email) == 0 {
66-
ctx.Redirect(models.DefaultAvatarLink())
72+
cacheableRedirect(ctx, models.DefaultAvatarLink())
6773
return
6874
}
6975
size := ctx.FormInt("size")
@@ -94,5 +100,5 @@ func AvatarByEmailHash(ctx *context.Context) {
94100
}
95101
}
96102

97-
ctx.Redirect(models.MakeFinalAvatarURL(avatarURL, size))
103+
cacheableRedirect(ctx, models.MakeFinalAvatarURL(avatarURL, size))
98104
}

services/gitdiff/gitdiff.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
996996

997997
// Create a new section to represent this hunk
998998
curSection = &DiffSection{}
999+
lastLeftIdx = -1
9991000
curFile.Sections = append(curFile.Sections, curSection)
10001001

10011002
lineSectionInfo := getDiffLineSectionInfo(curFile.Name, line, leftLine-1, rightLine-1)
@@ -1036,6 +1037,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
10361037
// Create a new section to represent this hunk
10371038
curSection = &DiffSection{}
10381039
curFile.Sections = append(curFile.Sections, curSection)
1040+
lastLeftIdx = -1
10391041
}
10401042
if lastLeftIdx > -1 {
10411043
diffLine.Match = lastLeftIdx
@@ -1061,6 +1063,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
10611063
// Create a new section to represent this hunk
10621064
curSection = &DiffSection{}
10631065
curFile.Sections = append(curFile.Sections, curSection)
1066+
lastLeftIdx = -1
10641067
}
10651068
if len(curSection.Lines) == 0 || curSection.Lines[len(curSection.Lines)-1].Type != DiffLineDel {
10661069
lastLeftIdx = len(curSection.Lines)
@@ -1121,6 +1124,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
11211124
curFile.IsBin = true
11221125
curFile.IsLFSFile = true
11231126
curSection.Lines = nil
1127+
lastLeftIdx = -1
11241128
}
11251129
}
11261130
}

templates/mail/issue/default.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
{{end -}}
6363
{{- range .ReviewComments}}
6464
<hr>
65-
{{.i18n.Tr "mail.issue.in_tree_path" .TreePath}}
65+
{{$.i18n.Tr "mail.issue.in_tree_path" .TreePath}}
6666
<div class="review">
6767
<pre>{{.Patch}}</pre>
6868
<div>{{.RenderedContent | Safe}}</div>

0 commit comments

Comments
 (0)