1
0
Fork 0

Merge pull request '[gitea] week 2024-37 cherry pick (gitea/main -> forgejo)' (#5263) from algernon/wcp/2024-37 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5263
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-09-11 10:34:35 +00:00
commit abd08e6fd8
6 changed files with 44 additions and 61 deletions

View file

@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" 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/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View file

@ -113,7 +113,24 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
var changes internal.RepoChanges var changes internal.RepoChanges
var err error var err error
updatedFilenames := make([]string, 0, 10) 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) line = strings.TrimSpace(line)
if len(line) == 0 { if len(line) == 0 {
continue continue
@ -161,15 +178,22 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
default: default:
log.Warn("Unrecognized status: %c (line=%s)", status, line) 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). if len(updatedFilenames) > 0 {
AddDashesAndList(updatedFilenames...) if err := updateChanges(); err != nil {
lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()}) return nil, err
if err != nil { }
return nil, err
} }
changes.Updates, err = parseGitLsTreeOutput(lsTreeStdout)
return &changes, err return &changes, err
} }

View file

@ -195,7 +195,7 @@ func GetAllCommits(ctx *context.APIContext) {
// get commit specified by sha // get commit specified by sha
baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha) baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommit", err) ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
return return
} }
} }

View file

@ -6,7 +6,6 @@ package explore
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"strings"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
@ -58,7 +57,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy db.SearchOrderBy orderBy db.SearchOrderBy
) )
sortOrder := strings.ToLower(ctx.FormString("sort")) sortOrder := ctx.FormString("sort")
if sortOrder == "" { if sortOrder == "" {
sortOrder = setting.UI.ExploreDefaultSort sortOrder = setting.UI.ExploreDefaultSort
} }

View file

@ -48,32 +48,12 @@ func Home(ctx *context.Context) {
ctx.Data["Title"] = org.DisplayName() ctx.Data["Title"] = org.DisplayName()
var orderBy db.SearchOrderBy var orderBy db.SearchOrderBy
ctx.Data["SortType"] = ctx.FormString("sort") sortOrder := ctx.FormString("sort")
switch ctx.FormString("sort") { if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok {
case "newest": sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for org home?
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
} }
ctx.Data["SortType"] = sortOrder
orderBy = repo_model.OrderByFlatMap[sortOrder]
keyword := ctx.FormTrim("q") keyword := ctx.FormTrim("q")
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword

View file

@ -112,32 +112,12 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
orderBy db.SearchOrderBy orderBy db.SearchOrderBy
) )
ctx.Data["SortType"] = ctx.FormString("sort") sortOrder := ctx.FormString("sort")
switch ctx.FormString("sort") { if _, ok := repo_model.OrderByFlatMap[sortOrder]; !ok {
case "newest": sortOrder = setting.UI.ExploreDefaultSort // TODO: add new default sort order for user home?
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
} }
ctx.Data["SortType"] = sortOrder
orderBy = repo_model.OrderByFlatMap[sortOrder]
keyword := ctx.FormTrim("q") keyword := ctx.FormTrim("q")
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword