From c4f5b2b53192ddf7f7585153a3f95ea8fd0f4861 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 18 Jul 2025 19:16:27 +0800 Subject: Don't use full-file highlight when there is a git diff textconv (#35114) Fix #35106 --- modules/git/attribute/attribute.go | 1 + services/gitdiff/gitdiff.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/git/attribute/attribute.go b/modules/git/attribute/attribute.go index adf323ef41..9c01cb339e 100644 --- a/modules/git/attribute/attribute.go +++ b/modules/git/attribute/attribute.go @@ -20,6 +20,7 @@ const ( GitlabLanguage = "gitlab-language" Lockable = "lockable" Filter = "filter" + Diff = "diff" ) var LinguistAttributes = []string{ diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index e2cd01e25c..7c99e049d5 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1191,7 +1191,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit return nil, err } - checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage}) + checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage, attribute.Diff}) if err != nil { return nil, err } @@ -1200,6 +1200,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit for _, diffFile := range diff.Files { isVendored := optional.None[bool]() isGenerated := optional.None[bool]() + attrDiff := optional.None[string]() attrs, err := checker.CheckPath(diffFile.Name) if err == nil { isVendored, isGenerated = attrs.GetVendored(), attrs.GetGenerated() @@ -1207,6 +1208,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit if language.Has() { diffFile.Language = language.Value() } + attrDiff = attrs.Get(attribute.Diff).ToString() } // Populate Submodule URLs @@ -1228,7 +1230,8 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit diffFile.Sections = append(diffFile.Sections, tailSection) } - if !setting.Git.DisableDiffHighlight { + shouldFullFileHighlight := !setting.Git.DisableDiffHighlight && attrDiff.Value() == "" + if shouldFullFileHighlight { if limitedContent.LeftContent != nil && limitedContent.LeftContent.buf.Len() < MaxDiffHighlightEntireFileSize { diffFile.highlightedLeftLines = highlightCodeLines(diffFile, true /* left */, limitedContent.LeftContent.buf.String()) } -- cgit v1.2.3