From f86ddd53f03b26403b5575098e24d5df9b4c2a80 Mon Sep 17 00:00:00 2001 From: badhezi Date: Mon, 12 May 2025 16:38:44 +0300 Subject: [PATCH] parse .raw and .diff optional compare parameters --- routers/api/packages/api.go | 1 - routers/common/compare.go | 1 + routers/web/repo/compare.go | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index ae4ea7ea87..8e8080b622 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -685,7 +685,6 @@ func CommonRoutes() *web.Router { // https://github.com/opencontainers/distribution-spec/blob/main/spec.md func ContainerRoutes() *web.Router { r := web.NewRouter() - r.Use(context.PackageContexter()) verifyAuth(r, []auth.Method{ diff --git a/routers/common/compare.go b/routers/common/compare.go index 4d1cc2f0d8..736f73db0e 100644 --- a/routers/common/compare.go +++ b/routers/common/compare.go @@ -18,4 +18,5 @@ type CompareInfo struct { BaseBranch string HeadBranch string DirectComparison bool + RawDiffType git.RawDiffType } diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 8b99dd95da..12ce37bcef 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -228,7 +228,19 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ) infoPath = ctx.PathParam("*") + var infos []string + + // Handle possible suffixes: .diff or .patch + if strings.HasSuffix(infoPath, ".diff") { + ci.RawDiffType = git.RawDiffNormal + infoPath = strings.TrimSuffix(infoPath, ".diff") + + } else if strings.HasSuffix(infoPath, ".patch") { + ci.RawDiffType = git.RawDiffPatch + infoPath = strings.TrimSuffix(infoPath, ".patch") + } + if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { @@ -743,6 +755,12 @@ func CompareDiff(ctx *context.Context) { return } + if ci.RawDiffType != "" { + git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp) + ctx.Resp.Flush() + return + } + baseTags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("GetTagNamesByRepoID", err)