From fa05b27afa6bf1838dd4e2b35381521ba19d3df6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 May 2026 09:56:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Adiff=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=97=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 2 +- routers/hat/repo/commits.go | 15 +++++++++++++-- routers/hat/repo/pull.go | 11 +++++++++-- routers/hat/repo/pull_version.go | 12 +++++++++++- routers/hat/repo/repo.go | 3 ++- services/gitdiff/gitdiff.go | 7 +++++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 9f736b2..4d255ec 100644 --- a/main.go +++ b/main.go @@ -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 = "" ) diff --git a/routers/hat/repo/commits.go b/routers/hat/repo/commits.go index 4274b4e..48c7c0a 100644 --- a/routers/hat/repo/commits.go +++ b/routers/hat/repo/commits.go @@ -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}) } diff --git a/routers/hat/repo/pull.go b/routers/hat/repo/pull.go index 1039c7e..e43a614 100644 --- a/routers/hat/repo/pull.go +++ b/routers/hat/repo/pull.go @@ -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, } diff --git a/routers/hat/repo/pull_version.go b/routers/hat/repo/pull_version.go index 22b4f39..a3a31ac 100644 --- a/routers/hat/repo/pull_version.go +++ b/routers/hat/repo/pull_version.go @@ -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 { diff --git a/routers/hat/repo/repo.go b/routers/hat/repo/repo.go index 278c8d2..d269f9a 100644 --- a/routers/hat/repo/repo.go +++ b/routers/hat/repo/repo.go @@ -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 } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 7d901b5..0b18a36 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -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