From 11a0410bd8c0507dfc17939fbbf39ddc44ee5369 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 f6ee5958b5..9ad7e5a976 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -532,7 +532,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 fda31a07ba..57edafa55a 100644 --- a/routers/common/compare.go +++ b/routers/common/compare.go @@ -19,4 +19,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 9262703078..dd2fb1b133 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -230,7 +230,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 { @@ -746,6 +758,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)