From 3ad20e27aef33fcd2ed075c46221d9174590fc7e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 1 Sep 2024 13:57:31 +0800 Subject: [PATCH 1/6] Fix index too many file names bug (#31903) Try to fix #31884 Fix #28584 (cherry picked from commit 286ede47ad683bf0431e531e82019cd016cc54dd) --- modules/indexer/code/git.go | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go index c5dfe43836..c7ffcfdd40 100644 --- a/modules/indexer/code/git.go +++ b/modules/indexer/code/git.go @@ -113,7 +113,24 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio var changes internal.RepoChanges var err error updatedFilenames := make([]string, 0, 10) - for _, line := range strings.Split(stdout, "\n") { + + updateChanges := func() error { + cmd := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l").AddDynamicArguments(revision). + AddDashesAndList(updatedFilenames...) + lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()}) + if err != nil { + return err + } + + updates, err1 := parseGitLsTreeOutput(lsTreeStdout) + if err1 != nil { + return err1 + } + changes.Updates = append(changes.Updates, updates...) + return nil + } + lines := strings.Split(stdout, "\n") + for _, line := range lines { line = strings.TrimSpace(line) if len(line) == 0 { continue @@ -161,15 +178,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio default: log.Warn("Unrecognized status: %c (line=%s)", status, line) } + + // According to https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation#more-information + // the command line length should less than 8191 characters, assume filepath is 256, then 8191/256 = 31, so we use 30 + if len(updatedFilenames) >= 30 { + if err := updateChanges(); err != nil { + return nil, err + } + updatedFilenames = updatedFilenames[0:0] + } } - cmd := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l").AddDynamicArguments(revision). - AddDashesAndList(updatedFilenames...) - lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()}) - if err != nil { - return nil, err + if len(updatedFilenames) > 0 { + if err := updateChanges(); err != nil { + return nil, err + } } - changes.Updates, err = parseGitLsTreeOutput(lsTreeStdout) return &changes, err } From 5a0bc357992dad725b0163105f8b6464ec130a21 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 2 Sep 2024 01:55:05 +0900 Subject: [PATCH 2/6] Fix sort order for organization home and user profile page (#31921) Fix #31916 In #30876, `sortOrder` has been changed into a map, but it is only implemented in explore. ~~But it seems that size sort order has no effect from long long ago,~~ not directly caused by the PR above. I think it is still caused by #29231. In #29231, it merged the sort orders from `templates/explore/repo_search.tmpl` and `templates/admin/repo/search.tmpl`. In `templates/admin/repo/search.tmpl`, it contains size sort orders, but not in `templates/explore/repo_search.tmpl`, which is used in non-admin pages. So `order by size` is added from #29231, but the handler was not added. --------- Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang (cherry picked from commit 661a1e10f7abd3527d2abc027dec936022db9379) --- routers/web/org/home.go | 30 +++++------------------------- routers/web/user/profile.go | 30 +++++------------------------- 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 1e04b72cbb..92793d95a4 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -48,32 +48,12 @@ func Home(ctx *context.Context) { ctx.Data["Title"] = org.DisplayName() var orderBy db.SearchOrderBy - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { - case "newest": - orderBy = db.SearchOrderByNewest - case "oldest": - orderBy = db.SearchOrderByOldest - case "recentupdate": - orderBy = db.SearchOrderByRecentUpdated - case "leastupdate": - orderBy = db.SearchOrderByLeastUpdated - case "reversealphabetically": - orderBy = db.SearchOrderByAlphabeticallyReverse - case "alphabetically": - orderBy = db.SearchOrderByAlphabetically - case "moststars": - orderBy = db.SearchOrderByStarsReverse - case "feweststars": - orderBy = db.SearchOrderByStars - case "mostforks": - orderBy = db.SearchOrderByForksReverse - case "fewestforks": - orderBy = db.SearchOrderByForks - default: - ctx.Data["SortType"] = "recentupdate" - orderBy = db.SearchOrderByRecentUpdated + sortOrder := ctx.FormString("sort") + if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok { + sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home? } + ctx.Data["SortType"] = sortOrder + orderBy = repo_model.OrderByFlatMap[sortOrder] keyword := ctx.FormTrim("q") ctx.Data["Keyword"] = keyword diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 3000792789..57b8d9da2f 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -112,32 +112,12 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb orderBy db.SearchOrderBy ) - ctx.Data["SortType"] = ctx.FormString("sort") - switch ctx.FormString("sort") { - case "newest": - orderBy = db.SearchOrderByNewest - case "oldest": - orderBy = db.SearchOrderByOldest - case "recentupdate": - orderBy = db.SearchOrderByRecentUpdated - case "leastupdate": - orderBy = db.SearchOrderByLeastUpdated - case "reversealphabetically": - orderBy = db.SearchOrderByAlphabeticallyReverse - case "alphabetically": - orderBy = db.SearchOrderByAlphabetically - case "moststars": - orderBy = db.SearchOrderByStarsReverse - case "feweststars": - orderBy = db.SearchOrderByStars - case "mostforks": - orderBy = db.SearchOrderByForksReverse - case "fewestforks": - orderBy = db.SearchOrderByForks - default: - ctx.Data["SortType"] = "recentupdate" - orderBy = db.SearchOrderByRecentUpdated + sortOrder := ctx.FormString("sort") + if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok { + sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home? } + ctx.Data["SortType"] = sortOrder + orderBy = repo_model.OrderByFlatMap[sortOrder] keyword := ctx.FormTrim("q") ctx.Data["Keyword"] = keyword From 4098098f00c108c4d5d6c9b7c76250c55b4a5df4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 1 Sep 2024 20:25:02 +0200 Subject: [PATCH 3/6] nix wording nit in todo code comment (cherry picked from commit c0db47bf9b6eb59d822ad21b7dd8b1d6acd8ad8e) --- routers/web/user/profile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 57b8d9da2f..9cb392d878 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -114,7 +114,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb sortOrder := ctx.FormString("sort") if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok { - sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home? + sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for user home? } ctx.Data["SortType"] = sortOrder orderBy = repo_model.OrderByFlatMap[sortOrder] From 3c8eb467653b67155b21022647ba44bc40767dee Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 5 Sep 2024 12:53:30 +0200 Subject: [PATCH 4/6] For consistency make repo search sort options case sensitive (#31951) (cherry picked from commit 19af5344623ba999f418520fad1a3bde77980561) --- routers/web/explore/repo.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index e978385b66..116b983b3a 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -6,7 +6,6 @@ package explore import ( "fmt" "net/http" - "strings" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" @@ -58,7 +57,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { orderBy db.SearchOrderBy ) - sortOrder := strings.ToLower(ctx.FormString("sort")) + sortOrder := ctx.FormString("sort") if sortOrder == "" { sortOrder = setting.UI.ExploreDefaultSort } From 5f3a2aafdf51e6af0d8cc50dc02c28718ca25882 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 5 Sep 2024 20:39:23 +0200 Subject: [PATCH 5/6] Return 404 instead of error when commit not exist (#31977) Fix #31976 (cherry picked from commit bf7ae0429cdf236510aa6702e499878bc2345a6e) --- routers/api/v1/repo/commits.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 5e7d10e6c2..c5e8cf99eb 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -195,7 +195,7 @@ func GetAllCommits(ctx *context.APIContext) { // get commit specified by sha baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetCommit", err) + ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err) return } } From 5f312250eb1b42cec5892ff62d863d69f0e5322a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 6 Sep 2024 15:20:30 +0800 Subject: [PATCH 6/6] Use forum.gitea.com instead of old URL (#31989) (cherry picked from commit a5818470fe62677d8859b590b2d80b98fe23d098) Signed-off-by: Gergely Nagy Conflicts: - .github/ISSUE_TEMPLATE/bug-report.yaml .github/ISSUE_TEMPLATE/config.yml .github/ISSUE_TEMPLATE/feature-request.yaml .github/ISSUE_TEMPLATE/ui.bug-report.yaml templates/install.tmpl All of these are Gitea-specific. Resolved the conflict by not picking their change. --- modules/activitypub/user_settings_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/activitypub/user_settings_test.go b/modules/activitypub/user_settings_test.go index 7ead81c129..f510e7a6ac 100644 --- a/modules/activitypub/user_settings_test.go +++ b/modules/activitypub/user_settings_test.go @@ -10,7 +10,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" - _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 + _ "code.gitea.io/gitea/models" // https://forum.gitea.com/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require"