diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2025-07-18 21:52:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-18 13:52:41 +0000 |
commit | 99596044d77c51b4e5d6a8c31925ba89481d8ad4 (patch) | |
tree | dcb0bb332488c23a9ff0a31070cad2b5fffd6b5f | |
parent | 693d26914fa3eafaa9b507a3fe99a2e717e0223e (diff) | |
download | gitea-release/v1.24.tar.gz gitea-release/v1.24.zip |
Don't use full-file highlight when there is a git diff textconv (#35114) (#35119)release/v1.24
Fix #35106
-rw-r--r-- | modules/git/attribute/attribute.go | 1 | ||||
-rw-r--r-- | 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 a10da8d5df..a3d2e39948 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1239,7 +1239,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 } @@ -1248,6 +1248,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() @@ -1255,6 +1256,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 @@ -1276,7 +1278,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()) } |