Skip to content

Commit 33044e0

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Fix incorrect ref commit ID usage (go-gitea#33331) Improve sync fork behavior (go-gitea#33319) Refactor response writer & access logger (go-gitea#33323)
2 parents 5f079b0 + 2e42e96 commit 33044e0

File tree

17 files changed

+283
-102
lines changed

17 files changed

+283
-102
lines changed

models/git/branch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
167167
BranchName: branchName,
168168
}
169169
}
170+
// FIXME: this design is not right: it doesn't check `branch.IsDeleted`, it doesn't make sense to make callers to check IsDeleted again and again.
171+
// It causes inconsistency with `GetBranches` and `git.GetBranch`, and will lead to strange bugs
172+
// In the future, there should be 2 functions: `GetBranchExisting` and `GetBranchWithDeleted`
170173
return &branch, nil
171174
}
172175

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ pulls.upstream_diverging_prompt_behind_1 = This branch is %[1]d commit behind %[
19531953
pulls.upstream_diverging_prompt_behind_n = This branch is %[1]d commits behind %[2]s
19541954
pulls.upstream_diverging_prompt_base_newer = The base branch %s has new changes
19551955
pulls.upstream_diverging_merge = Sync fork
1956-
pulls.upstream_diverging_merge_confirm = Would you like to merge base repository's default branch onto this repository's branch %s?
1956+
pulls.upstream_diverging_merge_confirm = Would you like to merge "%[1]s" onto "%[2]s"?
19571957

19581958
pull.deleted_branch = (deleted):%s
19591959
pull.agit_documentation = Review documentation about AGit

options/locale/locale_pt-PT.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,6 @@ pulls.upstream_diverging_prompt_behind_1=Este ramo está %[1]d cometimento atrá
19521952
pulls.upstream_diverging_prompt_behind_n=Este ramo está %[1]d cometimentos atrás de %[2]s
19531953
pulls.upstream_diverging_prompt_base_newer=O ramo base %s tem novas modificações
19541954
pulls.upstream_diverging_merge=Sincronizar derivação
1955-
pulls.upstream_diverging_merge_confirm=Gostaria de integrar o ramo principal do repositório base no ramo %s deste repositório?
19561955

19571956
pull.deleted_branch=(eliminado):%s
19581957
pull.agit_documentation=Rever a documentação sobre o AGit

routers/common/middleware.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ func ProtocolMiddlewares() (handlers []any) {
4343

4444
func RequestContextHandler() func(h http.Handler) http.Handler {
4545
return func(next http.Handler) http.Handler {
46-
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
47-
profDesc := fmt.Sprintf("%s: %s", req.Method, req.RequestURI)
46+
return http.HandlerFunc(func(respOrig http.ResponseWriter, req *http.Request) {
47+
// this response writer might not be the same as the one in context.Base.Resp
48+
// because there might be a "gzip writer" in the middle, so the "written size" here is the compressed size
49+
respWriter := context.WrapResponseWriter(respOrig)
50+
51+
profDesc := fmt.Sprintf("HTTP: %s %s", req.Method, req.RequestURI)
4852
ctx, finished := reqctx.NewRequestContext(req.Context(), profDesc)
4953
defer finished()
5054

5155
defer func() {
5256
if err := recover(); err != nil {
53-
RenderPanicErrorPage(resp, req, err) // it should never panic
57+
RenderPanicErrorPage(respWriter, req, err) // it should never panic
5458
}
5559
}()
5660

@@ -62,7 +66,7 @@ func RequestContextHandler() func(h http.Handler) http.Handler {
6266
_ = req.MultipartForm.RemoveAll() // remove the temp files buffered to tmp directory
6367
}
6468
})
65-
next.ServeHTTP(context.WrapResponseWriter(resp), req)
69+
next.ServeHTTP(respWriter, req)
6670
})
6771
}
6872
}

routers/web/repo/code_frequency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func CodeFrequency(ctx *context.Context) {
2929

3030
// CodeFrequencyData returns JSON of code frequency data
3131
func CodeFrequencyData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
32+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3333
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3434
ctx.Status(http.StatusAccepted)
3535
return

routers/web/repo/contributors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Contributors(ctx *context.Context) {
2626

2727
// ContributorsData renders JSON of contributors along with their weekly commit statistics
2828
func ContributorsData(ctx *context.Context) {
29-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
29+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3030
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3131
ctx.Status(http.StatusAccepted)
3232
return

routers/web/repo/recent_commits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func RecentCommits(ctx *context.Context) {
2929

3030
// RecentCommitsData returns JSON of recent commits data
3131
func RecentCommitsData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
32+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3333
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3434
ctx.Status(http.StatusAccepted)
3535
return

routers/web/repo/search.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ func Search(ctx *context.Context) {
6767
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
6868
}
6969
} else {
70+
searchRefName := git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch) // BranchName should be default branch or the first existing branch
7071
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
7172
ContextLineNumber: 1,
7273
IsFuzzy: prepareSearch.IsFuzzy,
73-
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
74+
RefName: searchRefName.String(),
7475
PathspecList: indexSettingToGitGrepPathspecList(),
7576
})
7677
if err != nil {
7778
// TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree.
7879
ctx.ServerError("GrepSearch", err)
7980
return
8081
}
82+
commitID, err := ctx.Repo.GitRepo.GetRefCommitID(searchRefName.String())
83+
if err != nil {
84+
ctx.ServerError("GetRefCommitID", err)
85+
return
86+
}
8187
total = len(res)
8288
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
8389
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
@@ -86,7 +92,7 @@ func Search(ctx *context.Context) {
8692
searchResults = append(searchResults, &code_indexer.Result{
8793
RepoID: ctx.Repo.Repository.ID,
8894
Filename: r.Filename,
89-
CommitID: ctx.Repo.CommitID,
95+
CommitID: commitID,
9096
// UpdatedUnix: not supported yet
9197
// Language: not supported yet
9298
// Color: not supported yet

routers/web/repo/setting/webhook.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ func TestWebhook(ctx *context.Context) {
655655
}
656656

657657
// Grab latest commit or fake one if it's empty repository.
658+
// Note: in old code, the "ctx.Repo.Commit" is the last commit of the default branch.
659+
// New code doesn't set that commit, so it always uses the fake commit to test webhook.
658660
commit := ctx.Repo.Commit
659661
if commit == nil {
660662
ghost := user_model.NewGhostUser()

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ func registerRoutes(m *web.Router) {
11461146
m.Post("/cancel", repo.MigrateCancelPost)
11471147
})
11481148
},
1149-
reqSignIn, context.RepoAssignment, reqRepoAdmin, context.RepoRef(),
1149+
reqSignIn, context.RepoAssignment, reqRepoAdmin,
11501150
ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer),
11511151
)
11521152
// end "/{username}/{reponame}/settings"
@@ -1513,7 +1513,7 @@ func registerRoutes(m *web.Router) {
15131513
m.Group("/activity_author_data", func() {
15141514
m.Get("", repo.ActivityAuthors)
15151515
m.Get("/{period}", repo.ActivityAuthors)
1516-
}, context.RepoRef(), repo.MustBeNotEmpty)
1516+
}, repo.MustBeNotEmpty)
15171517

15181518
m.Group("/archive", func() {
15191519
m.Get("/*", repo.Download)

0 commit comments

Comments
 (0)