From 513285460356084daf27c97efddcc585b2531c16 Mon Sep 17 00:00:00 2001 From: mirko Date: Sun, 15 Dec 2024 19:46:21 +0100 Subject: [PATCH] Add support for diff and patch compare --- routers/web/repo/compare.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 03d49fa692..27b1da13c2 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -231,6 +231,10 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { + infoPath, isDiff := strings.CutSuffix(infoPath, ".diff") + ctx.Data["DownloadDiff"] = isDiff + infoPath, isPatch := strings.CutSuffix(infoPath, ".patch") + ctx.Data["DownloadPatch"] = isPatch infos = strings.SplitN(infoPath, "...", 2) if len(infos) != 2 { if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 { @@ -717,6 +721,22 @@ func CompareDiff(ctx *context.Context) { return } + if ctx.Data["DownloadDiff"].(bool) { + err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch,git.RawDiffNormal,"", ctx.Resp) + if err != nil { + ctx.ServerError("GetDiff", err) + return + } + } + + if ctx.Data["DownloadPatch"].(bool) { + err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch,git.RawDiffPatch,"", ctx.Resp) + if err != nil { + ctx.ServerError("GetPatch", err) + return + } + } + ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["DirectComparison"] = ci.DirectComparison ctx.Data["OtherCompareSeparator"] = ".."