Skip to content

Commit ed52100

Browse files
committed
parse .raw and .diff optional compare parameters
1 parent a3c2953 commit ed52100

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
@@ -685,7 +685,6 @@ func CommonRoutes() *web.Router {
685685
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
686686
func ContainerRoutes() *web.Router {
687687
r := web.NewRouter()
688-
689688
r.Use(context.PackageContexter())
690689

691690
verifyAuth(r, []auth.Method{

routers/common/compare.go

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

routers/web/repo/compare.go

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

230230
infoPath = ctx.PathParam("*")
231+
231232
var infos []string
233+
234+
// Handle possible suffixes: .diff or .patch
235+
if strings.HasSuffix(infoPath, ".diff") {
236+
ci.RawDiffType = git.RawDiffNormal
237+
infoPath = strings.TrimSuffix(infoPath, ".diff")
238+
239+
} else if strings.HasSuffix(infoPath, ".patch") {
240+
ci.RawDiffType = git.RawDiffPatch
241+
infoPath = strings.TrimSuffix(infoPath, ".patch")
242+
}
243+
232244
if infoPath == "" {
233245
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
234246
} else {
@@ -743,6 +755,12 @@ func CompareDiff(ctx *context.Context) {
743755
return
744756
}
745757

758+
if ci.RawDiffType != "" {
759+
git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp)
760+
ctx.Resp.Flush()
761+
return
762+
}
763+
746764
baseTags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
747765
if err != nil {
748766
ctx.ServerError("GetTagNamesByRepoID", err)

0 commit comments

Comments
 (0)