From 27570ea685c0b02363c2bc60dbe07dbfa03dc53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tara=7E=20=E2=99=A1?= Date: Sun, 30 Aug 2026 16:17:32 +0200 Subject: [PATCH] enhance(repo): unify diff stats on commit pages, misc diff tweaks (#39134) Co-authored-by: silverwind Co-authored-by: wxiaoguang --- options/locale/locale_en-US.json | 15 ++++++++++----- routers/web/repo/commit.go | 2 ++ routers/web/repo/compare.go | 1 + routers/web/repo/pull.go | 1 + templates/repo/commit_page.tmpl | 9 ++++++++- templates/repo/diff/box.tmpl | 19 ++++++++++++------- web_src/css/modules/segment.css | 5 +---- web_src/css/repo.css | 23 +++++++---------------- web_src/css/review.css | 4 ---- web_src/js/components/DiffFileTree.vue | 2 -- 10 files changed, 42 insertions(+), 39 deletions(-) diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 7753c6d71c0..1d947b6deb8 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -2593,16 +2593,21 @@ "repo.diff.whitespace_ignore_at_eol": "Ignore changes in whitespace at EOL", "repo.diff.stats_desc": " %d changed files with %d additions and %d deletions", "repo.diff.stats_desc_file": "%d changes: %d additions and %d deletions", + "repo.diff.num_files_changed_1": "%d file changed", + "repo.diff.num_files_changed_n": "%d files changed", "repo.diff.bin": "BIN", "repo.diff.bin_not_shown": "Binary file not shown.", + "repo.diff.file_renamed_no_changes": "File renamed without changes.", + "repo.diff.file_mode_changed": "File mode changed.", + "repo.diff.file_whitespace_only_changes": "Whitespace-only changes.", "repo.diff.view_file": "View File", "repo.diff.file_before": "Before", "repo.diff.file_after": "After", "repo.diff.file_image_width": "Width", "repo.diff.file_image_height": "Height", "repo.diff.file_byte_size": "Size", - "repo.diff.file_suppressed": "File diff suppressed because it is too large", - "repo.diff.file_suppressed_line_too_long": "File diff suppressed because one or more lines are too long", + "repo.diff.file_suppressed": "File diff suppressed because it is too large.", + "repo.diff.file_suppressed_line_too_long": "File diff suppressed because one or more lines are too long.", "repo.diff.too_many_files": "Loaded %[1]d of %[2]d files, more files were not shown because too many files have changed in this diff.", "repo.diff.show_more": "Show more", "repo.diff.load": "Load diff", @@ -2642,9 +2647,9 @@ "repo.diff.all_file_extensions": "All extensions", "repo.diff.no_files_matched": "No files matched your search", "repo.diff.show_more_matching": "Show more - %[1]d matching below", - "repo.diff.submodule_added": "Submodule %[1]s added at %[2]s", - "repo.diff.submodule_deleted": "Submodule %[1]s deleted from %[2]s", - "repo.diff.submodule_updated": "Submodule %[1]s updated: %[2]s", + "repo.diff.submodule_added": "Submodule %[1]s added at %[2]s.", + "repo.diff.submodule_deleted": "Submodule %[1]s deleted from %[2]s.", + "repo.diff.submodule_updated": "Submodule %[1]s updated: %[2]s.", "repo.releases.desc": "Track project versions and downloads.", "repo.release.releases": "Releases", "repo.release.detail": "Release details", diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index c2286a94853..2b5978defad 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -395,6 +395,8 @@ func Diff(ctx *context.Context) { ctx.Data["CommitOtherParticipants"] = gituser.BuildAvatarStackData(ctx, commit.CoAuthorIdentities(), nil).Participants ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diffShortStat.NumFiles == 0 + ctx.Data["ShowDiffSummaryInToolbar"] = false + ctx.Data["ShowDiffSummaryInCommitHeader"] = diffShortStat.NumFiles != 0 if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) { return repo_model.HasAccessToRepoCodeUnit(ctx, ctx.Repo.Repository, user.ID) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index a5f225cefba..f68e3d2c332 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -438,6 +438,7 @@ func (cpi *comparePageInfoType) prepareCompareDiff(ctx *context.Context, whitesp AfterCommitID: headCommitID, } ctx.Data["DiffNotAvailable"] = diffShortStat.NumFiles == 0 + ctx.Data["ShowDiffSummaryInToolbar"] = diffShortStat.NumFiles != 0 if !fileOnly { diffTree, err := gitdiff.GetDiffTree(ctx, ci.HeadGitRepo, false, beforeCommitID, headCommitID) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 9caba3ae3a4..4ea89b7d84b 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -871,6 +871,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { AfterCommitID: afterCommitID, } ctx.Data["DiffNotAvailable"] = diffShortStat.NumFiles == 0 + ctx.Data["ShowDiffSummaryInToolbar"] = diffShortStat.NumFiles != 0 if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, issue, ctx.Doer); err != nil { ctx.ServerError("CanMarkConversation", err) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index fd9ff52ce0f..f8e9971dcaa 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -125,7 +125,7 @@ {{template "repo/commit_load_branches_and_tags" .}} -
+
{{if .Author}} {{ctx.AvatarUtils.Avatar .Author 20}} @@ -192,6 +192,13 @@
+ {{if .ShowDiffSummaryInCommitHeader}} +
+ {{ctx.Locale.TrN .DiffShortStat.NumFiles "repo.diff.num_files_changed_1" "repo.diff.num_files_changed_n" .DiffShortStat.NumFiles}} + {{template "repo/diff/stats" dict "Addition" .DiffShortStat.TotalAddition "Deletion" .DiffShortStat.TotalDeletion}} +
+ {{end}} + {{if .NoteRendered}}
{{svg "octicon-note" 16 "tw-mr-2"}} diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 3b329b1b2dc..8f62fcc8c3d 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -17,7 +17,7 @@ diffTreeBtn.setAttribute('data-tooltip-content', diffTreeBtn.getAttribute(diffTreeVisible ? 'data-hide-text' : 'data-show-text')); {{end}} - {{if not .DiffNotAvailable}} + {{if .ShowDiffSummaryInToolbar}}
{{svg "octicon-diff" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.diff.stats_desc" .DiffShortStat.NumFiles .DiffShortStat.TotalAddition .DiffShortStat.TotalDeletion}}
@@ -91,13 +91,12 @@ {{$isImage:= $file.IsBlobTypeImage}} {{$isCsv := $file.IsBlobTypeCsv}} {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} - {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}} {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.Repository.IsArchived) $.IsShowingAllCommits}} -
+
-