mirror of
https://github.com/go-gitea/gitea
synced 2025-01-21 23:24:29 +00:00
Fix incorrect ref commit ID usage (#33331)
After the RefName refactoring, the `ctx.Repo.CommitID` is only set when there is a `RepoRefByType` middleware. Many handlers do not use that middleware and they only use "default branch"
This commit is contained in:
parent
39de2955fd
commit
6cc1067884
@ -29,7 +29,7 @@ func CodeFrequency(ctx *context.Context) {
|
|||||||
|
|
||||||
// CodeFrequencyData returns JSON of code frequency data
|
// CodeFrequencyData returns JSON of code frequency data
|
||||||
func CodeFrequencyData(ctx *context.Context) {
|
func CodeFrequencyData(ctx *context.Context) {
|
||||||
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
|
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
|
||||||
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
||||||
ctx.Status(http.StatusAccepted)
|
ctx.Status(http.StatusAccepted)
|
||||||
return
|
return
|
||||||
|
@ -26,7 +26,7 @@ func Contributors(ctx *context.Context) {
|
|||||||
|
|
||||||
// ContributorsData renders JSON of contributors along with their weekly commit statistics
|
// ContributorsData renders JSON of contributors along with their weekly commit statistics
|
||||||
func ContributorsData(ctx *context.Context) {
|
func ContributorsData(ctx *context.Context) {
|
||||||
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
|
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
|
||||||
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
||||||
ctx.Status(http.StatusAccepted)
|
ctx.Status(http.StatusAccepted)
|
||||||
return
|
return
|
||||||
|
@ -29,7 +29,7 @@ func RecentCommits(ctx *context.Context) {
|
|||||||
|
|
||||||
// RecentCommitsData returns JSON of recent commits data
|
// RecentCommitsData returns JSON of recent commits data
|
||||||
func RecentCommitsData(ctx *context.Context) {
|
func RecentCommitsData(ctx *context.Context) {
|
||||||
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
|
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
|
||||||
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
||||||
ctx.Status(http.StatusAccepted)
|
ctx.Status(http.StatusAccepted)
|
||||||
return
|
return
|
||||||
|
@ -67,10 +67,11 @@ func Search(ctx *context.Context) {
|
|||||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
searchRefName := git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch) // BranchName should be default branch or the first existing branch
|
||||||
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
|
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
|
||||||
ContextLineNumber: 1,
|
ContextLineNumber: 1,
|
||||||
IsFuzzy: prepareSearch.IsFuzzy,
|
IsFuzzy: prepareSearch.IsFuzzy,
|
||||||
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
|
RefName: searchRefName.String(),
|
||||||
PathspecList: indexSettingToGitGrepPathspecList(),
|
PathspecList: indexSettingToGitGrepPathspecList(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,6 +79,11 @@ func Search(ctx *context.Context) {
|
|||||||
ctx.ServerError("GrepSearch", err)
|
ctx.ServerError("GrepSearch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
commitID, err := ctx.Repo.GitRepo.GetRefCommitID(searchRefName.String())
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetRefCommitID", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
total = len(res)
|
total = len(res)
|
||||||
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
|
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
|
||||||
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
|
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
|
||||||
@ -86,7 +92,7 @@ func Search(ctx *context.Context) {
|
|||||||
searchResults = append(searchResults, &code_indexer.Result{
|
searchResults = append(searchResults, &code_indexer.Result{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Filename: r.Filename,
|
Filename: r.Filename,
|
||||||
CommitID: ctx.Repo.CommitID,
|
CommitID: commitID,
|
||||||
// UpdatedUnix: not supported yet
|
// UpdatedUnix: not supported yet
|
||||||
// Language: not supported yet
|
// Language: not supported yet
|
||||||
// Color: not supported yet
|
// Color: not supported yet
|
||||||
|
@ -654,6 +654,8 @@ func TestWebhook(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab latest commit or fake one if it's empty repository.
|
// Grab latest commit or fake one if it's empty repository.
|
||||||
|
// Note: in old code, the "ctx.Repo.Commit" is the last commit of the default branch.
|
||||||
|
// New code doesn't set that commit, so it always uses the fake commit to test webhook.
|
||||||
commit := ctx.Repo.Commit
|
commit := ctx.Repo.Commit
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
ghost := user_model.NewGhostUser()
|
ghost := user_model.NewGhostUser()
|
||||||
|
@ -1146,7 +1146,7 @@ func registerRoutes(m *web.Router) {
|
|||||||
m.Post("/cancel", repo.MigrateCancelPost)
|
m.Post("/cancel", repo.MigrateCancelPost)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
reqSignIn, context.RepoAssignment, reqRepoAdmin, context.RepoRef(),
|
reqSignIn, context.RepoAssignment, reqRepoAdmin,
|
||||||
ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer),
|
ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer),
|
||||||
)
|
)
|
||||||
// end "/{username}/{reponame}/settings"
|
// end "/{username}/{reponame}/settings"
|
||||||
@ -1513,7 +1513,7 @@ func registerRoutes(m *web.Router) {
|
|||||||
m.Group("/activity_author_data", func() {
|
m.Group("/activity_author_data", func() {
|
||||||
m.Get("", repo.ActivityAuthors)
|
m.Get("", repo.ActivityAuthors)
|
||||||
m.Get("/{period}", repo.ActivityAuthors)
|
m.Get("/{period}", repo.ActivityAuthors)
|
||||||
}, context.RepoRef(), repo.MustBeNotEmpty)
|
}, repo.MustBeNotEmpty)
|
||||||
|
|
||||||
m.Group("/archive", func() {
|
m.Group("/archive", func() {
|
||||||
m.Get("/*", repo.Download)
|
m.Get("/*", repo.Download)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user