From 0e46499258a20a8d701cdfc489c55a4246b4901e Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 3 Dec 2022 15:47:00 +0000 Subject: [PATCH 1/8] Do not emit ambiguous character warning on rendered pages (#22016) The real sensitivity of ambiguous characters is in source code - therefore warning about them in rendered pages causes too many warnings. Therefore simply remove the warning on rendered pages. The escape button will remain available and it is present on the view source page. Fix #20999 Signed-off-by: Andrew Thornton --- templates/repo/view_file.tmpl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 0fe0a131985dd..9d82cc018c792 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -58,7 +58,9 @@
- {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}} + {{if not (or .IsMarkup .IsRenderedHTML)}} + {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}} + {{end}}
{{if .IsMarkup}} {{if .FileContent}}{{.FileContent | Safe}}{{end}} From d084ce306aabd99ee4d63934984544ee61760b27 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 4 Dec 2022 00:19:34 +0000 Subject: [PATCH 2/8] [skip ci] Updated licenses and gitignores --- options/gitignore/Bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/gitignore/Bazel b/options/gitignore/Bazel index 4e1d5a2ba0a42..bc3afc20ba696 100644 --- a/options/gitignore/Bazel +++ b/options/gitignore/Bazel @@ -6,7 +6,7 @@ /bazel-* # Directories for the Bazel IntelliJ plugin containing the generated -# IntelliJ project files and plugin configuration. Separate directories are +# IntelliJ project files and plugin configuration. Seperate directories are # for the IntelliJ, Android Studio and CLion versions of the plugin. /.ijwb/ /.aswb/ From 9eb9cf5153160e38a25dbbdeeb223fac769879db Mon Sep 17 00:00:00 2001 From: Percy Ma Date: Sun, 4 Dec 2022 16:56:10 +0800 Subject: [PATCH 3/8] fix(web): reduce page jitter on browsers that support overlay scrollbar (#21850) Reduce jitter caused by the presence or absence of scrollbars in page switching --- Ref [scrollbar-gutter | MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-gutter) https://user-images.githubusercontent.com/45708948/165972251-7d5a5017-f76d-4ba2-9106-a224b3ee521f.mp4 --- web_src/less/_base.less | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web_src/less/_base.less b/web_src/less/_base.less index 14b69dec49a63..e156ccd6cc0ad 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -222,6 +222,13 @@ body { overflow-wrap: break-word; } +@supports (overflow: overlay) { + body { + overflow: overlay; + scrollbar-gutter: stable; + } +} + img { border-radius: 3px; } From 36cbaec54cb4640e23a1edb3ba6d488867f73302 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 4 Dec 2022 16:57:17 +0800 Subject: [PATCH 4/8] Fix ListBranches to handle empty case (#21921) Fix #21910 Co-authored-by: KN4CK3R --- routers/api/v1/repo/branch.go | 60 ++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index f5b1eb1c42c2d..3060cf24064d5 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -251,42 +251,50 @@ func ListBranches(ctx *context.APIContext) { // "200": // "$ref": "#/responses/BranchList" + var totalNumOfBranches int + var apiBranches []*api.Branch + listOptions := utils.GetListOptions(ctx) - skip, _ := listOptions.GetStartEnd() - branches, totalNumOfBranches, err := ctx.Repo.GitRepo.GetBranches(skip, listOptions.PageSize) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetBranches", err) - return - } - apiBranches := make([]*api.Branch, 0, len(branches)) - for i := range branches { - c, err := branches[i].GetCommit() + if !ctx.Repo.Repository.IsEmpty && ctx.Repo.GitRepo != nil { + skip, _ := listOptions.GetStartEnd() + branches, total, err := ctx.Repo.GitRepo.GetBranches(skip, listOptions.PageSize) if err != nil { - // Skip if this branch doesn't exist anymore. - if git.IsErrNotExist(err) { - totalNumOfBranches-- - continue - } - ctx.Error(http.StatusInternalServerError, "GetCommit", err) + ctx.Error(http.StatusInternalServerError, "GetBranches", err) return } - branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) - return - } - apiBranch, err := convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) - if err != nil { - ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err) - return + + apiBranches = make([]*api.Branch, 0, len(branches)) + for i := range branches { + c, err := branches[i].GetCommit() + if err != nil { + // Skip if this branch doesn't exist anymore. + if git.IsErrNotExist(err) { + total-- + continue + } + ctx.Error(http.StatusInternalServerError, "GetCommit", err) + return + } + branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err) + return + } + apiBranch, err := convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) + if err != nil { + ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err) + return + } + apiBranches = append(apiBranches, apiBranch) } - apiBranches = append(apiBranches, apiBranch) + + totalNumOfBranches = total } ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize) ctx.SetTotalCountHeader(int64(totalNumOfBranches)) - ctx.JSON(http.StatusOK, &apiBranches) + ctx.JSON(http.StatusOK, apiBranches) } // GetBranchProtection gets a branch protection From 46485848fa8580d7d1994e602590d5ac981110b7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 4 Dec 2022 11:28:57 +0100 Subject: [PATCH 5/8] On tag/branch-exist check, dont panic if repo is nil (#21787) fix a panic found in gitea logs --- modules/git/repo_branch_nogogit.go | 2 +- modules/git/repo_tag_nogogit.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index b1d0df6474a8c..7559513c9b433 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -52,7 +52,7 @@ func (repo *Repository) IsReferenceExist(name string) bool { // IsBranchExist returns true if given branch exists in current repository. func (repo *Repository) IsBranchExist(name string) bool { - if name == "" { + if repo == nil || name == "" { return false } diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go index 1fb631002b779..d3331cf9b73e1 100644 --- a/modules/git/repo_tag_nogogit.go +++ b/modules/git/repo_tag_nogogit.go @@ -15,7 +15,7 @@ import ( // IsTagExist returns true if given tag exists in the repository. func (repo *Repository) IsTagExist(name string) bool { - if name == "" { + if repo == nil || name == "" { return false } From 84d2a820e59f0d96d818d40205d705deab2af576 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Sun, 4 Dec 2022 12:12:06 +0100 Subject: [PATCH 6/8] Add dumb-init to rootless docker (#21775) Add dumb-init as process reaper to the rootless image to reap defunct git processes. --- Dockerfile.rootless | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 46a14eae87352..a43a63fa10c78 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -31,6 +31,7 @@ EXPOSE 2222 3000 RUN apk --no-cache add \ bash \ ca-certificates \ + dumb-init \ gettext \ git \ curl \ @@ -68,6 +69,6 @@ ENV HOME "/var/lib/gitea/git" VOLUME ["/var/lib/gitea", "/etc/gitea"] WORKDIR /var/lib/gitea -ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"] CMD [] From ea86c2b56afeca6450a3e1081c0fd417a09e5434 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 4 Dec 2022 17:48:18 +0000 Subject: [PATCH 7/8] Use GhostUser if needed for TrackedTimes (#22021) When getting tracked times out of the db and loading their attributes handle not exist errors in a nicer way. (Also prevent an NPE.) Fix #22006 Signed-off-by: Andrew Thornton --- models/issues/tracked_time.go | 27 ++++++++++++++++++--------- modules/convert/issue.go | 11 +++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go index 2de63a3a45a3b..554b01bd407cc 100644 --- a/models/issues/tracked_time.go +++ b/models/issues/tracked_time.go @@ -5,6 +5,7 @@ package issues import ( "context" + "errors" "time" "code.gitea.io/gitea/models/db" @@ -46,33 +47,41 @@ func (t *TrackedTime) LoadAttributes() (err error) { } func (t *TrackedTime) loadAttributes(ctx context.Context) (err error) { + // Load the issue if t.Issue == nil { t.Issue, err = GetIssueByID(ctx, t.IssueID) - if err != nil { - return + if err != nil && !errors.Is(err, util.ErrNotExist) { + return err } + } + // Now load the repo for the issue (which we may have just loaded) + if t.Issue != nil { err = t.Issue.LoadRepo(ctx) - if err != nil { - return + if err != nil && !errors.Is(err, util.ErrNotExist) { + return err } } + // Load the user if t.User == nil { t.User, err = user_model.GetUserByID(ctx, t.UserID) if err != nil { - return + if !errors.Is(err, util.ErrNotExist) { + return err + } + t.User = user_model.NewGhostUser() } } - return err + return nil } // LoadAttributes load Issue, User -func (tl TrackedTimeList) LoadAttributes() (err error) { +func (tl TrackedTimeList) LoadAttributes() error { for _, t := range tl { - if err = t.LoadAttributes(); err != nil { + if err := t.LoadAttributes(); err != nil { return err } } - return err + return nil } // FindTrackedTimesOptions represent the filters for tracked times. If an ID is 0 it will be ignored. diff --git a/modules/convert/issue.go b/modules/convert/issue.go index 221aeb885a9f2..3bc10065073a0 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -110,12 +110,11 @@ func ToAPIIssueList(ctx context.Context, il issues_model.IssueList) []*api.Issue // ToTrackedTime converts TrackedTime to API format func ToTrackedTime(ctx context.Context, t *issues_model.TrackedTime) (apiT *api.TrackedTime) { apiT = &api.TrackedTime{ - ID: t.ID, - IssueID: t.IssueID, - UserID: t.UserID, - UserName: t.User.Name, - Time: t.Time, - Created: t.Created, + ID: t.ID, + IssueID: t.IssueID, + UserID: t.UserID, + Time: t.Time, + Created: t.Created, } if t.Issue != nil { apiT.Issue = ToAPIIssue(ctx, t.Issue) From a08584ee367d42de56c5ba6a0fd36ac1067578dd Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 4 Dec 2022 17:57:30 +0000 Subject: [PATCH 8/8] Ensure that Chinese punctuation is not ambiguous when locale is Chinese (#22019) Although there are per-locale fallbacks for ambiguity the locale names for Chinese do not quite match our locales. This PR simply maps zh-CN on to zh-hans and other zh variants on to zh-hant. Ref #20999 Signed-off-by: Andrew Thornton --- modules/charset/ambiguous.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/charset/ambiguous.go b/modules/charset/ambiguous.go index c5b0c2c54d2e6..96e0561e155ab 100644 --- a/modules/charset/ambiguous.go +++ b/modules/charset/ambiguous.go @@ -28,6 +28,12 @@ func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable { key = key[:idx] } } + if table == nil && (locale.Language() == "zh-CN" || locale.Language() == "zh_CN") { + table = AmbiguousCharacters["zh-hans"] + } + if table == nil && strings.HasPrefix(locale.Language(), "zh") { + table = AmbiguousCharacters["zh-hant"] + } if table == nil { table = AmbiguousCharacters["_default"] }