parse .raw and .diff optional compare parameters

This commit is contained in:
badhezi 2025-05-12 16:38:44 +03:00
parent a3c29538f1
commit ed52100a1a
3 changed files with 19 additions and 1 deletions

View File

@ -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{

View File

@ -18,4 +18,5 @@ type CompareInfo struct {
BaseBranch string
HeadBranch string
DirectComparison bool
RawDiffType git.RawDiffType
}

View File

@ -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)