Skip to content

Commit 9959604

Browse files
authored
Don't use full-file highlight when there is a git diff textconv (go-gitea#35114) (go-gitea#35119)
Fix go-gitea#35106
1 parent 693d269 commit 9959604

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

modules/git/attribute/attribute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
GitlabLanguage = "gitlab-language"
2121
Lockable = "lockable"
2222
Filter = "filter"
23+
Diff = "diff"
2324
)
2425

2526
var LinguistAttributes = []string{

services/gitdiff/gitdiff.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
12391239
return nil, err
12401240
}
12411241

1242-
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage})
1242+
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage, attribute.Diff})
12431243
if err != nil {
12441244
return nil, err
12451245
}
@@ -1248,13 +1248,15 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
12481248
for _, diffFile := range diff.Files {
12491249
isVendored := optional.None[bool]()
12501250
isGenerated := optional.None[bool]()
1251+
attrDiff := optional.None[string]()
12511252
attrs, err := checker.CheckPath(diffFile.Name)
12521253
if err == nil {
12531254
isVendored, isGenerated = attrs.GetVendored(), attrs.GetGenerated()
12541255
language := attrs.GetLanguage()
12551256
if language.Has() {
12561257
diffFile.Language = language.Value()
12571258
}
1259+
attrDiff = attrs.Get(attribute.Diff).ToString()
12581260
}
12591261

12601262
// Populate Submodule URLs
@@ -1276,7 +1278,8 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
12761278
diffFile.Sections = append(diffFile.Sections, tailSection)
12771279
}
12781280

1279-
if !setting.Git.DisableDiffHighlight {
1281+
shouldFullFileHighlight := !setting.Git.DisableDiffHighlight && attrDiff.Value() == ""
1282+
if shouldFullFileHighlight {
12801283
if limitedContent.LeftContent != nil && limitedContent.LeftContent.buf.Len() < MaxDiffHighlightEntireFileSize {
12811284
diffFile.highlightedLeftLines = highlightCodeLines(diffFile, true /* left */, limitedContent.LeftContent.buf.String())
12821285
}

0 commit comments

Comments
 (0)