Skip to content

Commit 86c2371

Browse files
committed
parse .raw and .diff optional compare parameters
1 parent dcaeb90 commit 86c2371

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

routers/api/packages/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ func CommonRoutes() *web.Router {
532532
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
533533
func ContainerRoutes() *web.Router {
534534
r := web.NewRouter()
535-
536535
r.Use(context.PackageContexter())
537536

538537
verifyAuth(r, []auth.Method{

routers/common/compare.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ type CompareInfo struct {
1919
BaseBranch string
2020
HeadBranch string
2121
DirectComparison bool
22+
RawDiffType git.RawDiffType
2223
}

routers/web/repo/compare.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,19 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
230230
)
231231

232232
infoPath = ctx.PathParam("*")
233+
233234
var infos []string
235+
236+
// Handle possible suffixes: .diff or .patch
237+
if strings.HasSuffix(infoPath, ".diff") {
238+
ci.RawDiffType = git.RawDiffNormal
239+
infoPath = strings.TrimSuffix(infoPath, ".diff")
240+
241+
} else if strings.HasSuffix(infoPath, ".patch") {
242+
ci.RawDiffType = git.RawDiffPatch
243+
infoPath = strings.TrimSuffix(infoPath, ".patch")
244+
}
245+
234246
if infoPath == "" {
235247
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
236248
} else {
@@ -746,6 +758,12 @@ func CompareDiff(ctx *context.Context) {
746758
return
747759
}
748760

761+
if ci.RawDiffType != "" {
762+
git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp)
763+
ctx.Resp.Flush()
764+
return
765+
}
766+
749767
baseTags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
750768
if err != nil {
751769
ctx.ServerError("GetTagNamesByRepoID", err)

0 commit comments

Comments
 (0)