修复:diff适配旧版

This commit is contained in:
yystopf 2026-05-07 09:56:11 +08:00
parent 11249b31b1
commit fa05b27afa
6 changed files with 43 additions and 7 deletions

View File

@ -22,7 +22,7 @@ import (
)
var (
Version = "v3.0.1, by v1.25.1, 20260427 "
Version = "v3.0.2, by v1.25.1, 20260427 "
Tags = ""
MakeVersion = ""
)

View File

@ -19,6 +19,7 @@ import (
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
hat_gitdiff "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/gitdiff"
)
func GetAllCommitsSliceByTime(ctx *context.APIContext) {
@ -415,8 +416,13 @@ func GetCommitFilesByPath(ctx *context.APIContext) {
ctx.APIErrorNotFound(err)
return
}
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, "", commitID)
if err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, &diff)
ctx.JSON(http.StatusOK, &hat_gitdiff.Diff{Diff: diff, NumFiles: diffShortStat.NumFiles, TotalAddition: diffShortStat.TotalAddition, TotalDeletion: diffShortStat.TotalDeletion})
}
@ -448,5 +454,10 @@ func GetCommitDiff(ctx *context.APIContext) {
ctx.APIErrorNotFound(err)
return
}
ctx.JSON(http.StatusOK, &diff)
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, "", commitID)
if err != nil {
ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, &hat_gitdiff.Diff{Diff: diff, NumFiles: diffShortStat.NumFiles, TotalAddition: diffShortStat.TotalAddition, TotalDeletion: diffShortStat.TotalDeletion})
}

View File

@ -32,6 +32,7 @@ import (
pull_service "code.gitea.io/gitea/services/pull"
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
hat_gitdiff "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/gitdiff"
hat_pull_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/pull"
)
@ -573,11 +574,17 @@ func GetPullFilesByPath(ctx *context.APIContext) {
return
}
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, startCommitID, endCommitID)
if err != nil {
ctx.APIErrorInternal(err)
return
}
fileDiff := struct {
*gitdiff.Diff
*hat_gitdiff.Diff
LatestSha string
}{
Diff: diff,
Diff: &hat_gitdiff.Diff{Diff: diff, NumFiles: diffShortStat.NumFiles, TotalAddition: diffShortStat.TotalAddition, TotalDeletion: diffShortStat.TotalDeletion},
LatestSha: endCommitID,
}

View File

@ -84,10 +84,20 @@ func GetPullRequestVersionDiff(ctx *context.APIContext) {
if err != nil {
ctx.APIErrorInternal(err)
}
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, prv.BaseCommitID, prv.HeadCommitID)
if err != nil {
ctx.APIErrorInternal(err)
return
}
filepath := ctx.FormString("filepath")
if filepath == "" {
ctx.JSON(http.StatusOK, diffs)
ctx.JSON(http.StatusOK, &hat_gitdiff.Diff{
Diff: diffs,
NumFiles: diffShortStat.NumFiles,
TotalAddition: diffShortStat.TotalAddition,
TotalDeletion: diffShortStat.TotalDeletion,
})
} else {
targetDiffFile := &hat_gitdiff.DiffFile{}
for _, file := range diffs.Files {

View File

@ -30,6 +30,7 @@ import (
hat_convert "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
hat_git "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/git"
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
hat_gitdiff "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/gitdiff"
hat_repo_service "code.gitlink.org.cn/Gitlink/gitea_hat.git/services/repository"
)
@ -96,7 +97,7 @@ func PrepareComapreDiff(
ctx.Data["Diff"] = nil
ctx.Data["DiffNotAvailable"] = true
} else {
ctx.Data["Diff"] = diff
ctx.Data["Diff"] = &hat_gitdiff.Diff{Diff: diff, NumFiles: diffShortStat.NumFiles, TotalAddition: diffShortStat.TotalAddition, TotalDeletion: diffShortStat.TotalDeletion}
ctx.Data["DiffNotAvailable"] = false
}

View File

@ -4,6 +4,13 @@ import (
gitea_gitdiff "code.gitea.io/gitea/services/gitdiff"
)
type Diff struct {
*gitea_gitdiff.Diff
NumFiles int
TotalAddition int
TotalDeletion int
}
type DiffFile struct {
*gitea_gitdiff.DiffFile
Diff string