Add support for diff and patch compare

This commit is contained in:
mirko 2024-12-15 19:46:21 +01:00
parent 4b69aa5c10
commit 5132854603

View file

@ -231,6 +231,10 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
if infoPath == "" { if infoPath == "" {
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
} else { } 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) infos = strings.SplitN(infoPath, "...", 2)
if len(infos) != 2 { if len(infos) != 2 {
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 { if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
@ -717,6 +721,22 @@ func CompareDiff(ctx *context.Context) {
return 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["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
ctx.Data["DirectComparison"] = ci.DirectComparison ctx.Data["DirectComparison"] = ci.DirectComparison
ctx.Data["OtherCompareSeparator"] = ".." ctx.Data["OtherCompareSeparator"] = ".."