Skip to content

Commit a7eaa72

Browse files
committed
Exclude files from diff.
1 parent b5e46e2 commit a7eaa72

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,7 @@ diff.stats_desc = <strong> %d changed files</strong> with <strong>%d additions</
19561956
diff.stats_desc_file = %d changes: %d additions and %d deletions
19571957
diff.bin = BIN
19581958
diff.bin_not_shown = Binary file not shown.
1959+
diff.generated_not_shown = Generated file not shown.
19591960
diff.view_file = View File
19601961
diff.file_before = Before
19611962
diff.file_after = After

services/gitdiff/gitdiff.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ type DiffFile struct {
590590
IsIncomplete bool
591591
IsIncompleteLineTooLong bool
592592
IsProtected bool
593+
IsGenerated bool
593594
}
594595

595596
// GetType returns type of diff file.
@@ -1248,13 +1249,31 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
12481249
if err != nil {
12491250
return nil, fmt.Errorf("ParsePatch: %v", err)
12501251
}
1252+
1253+
var filenames []string
12511254
for _, diffFile := range diff.Files {
1255+
filenames = append(filenames, diffFile.Name)
1256+
12521257
tailSection := diffFile.GetTailSection(gitRepo, beforeCommitID, afterCommitID)
12531258
if tailSection != nil {
12541259
diffFile.Sections = append(diffFile.Sections, tailSection)
12551260
}
12561261
}
12571262

1263+
filename2attribute2info, err := gitRepo.CheckAttribute(git.CheckAttributeOpts{
1264+
Attributes: []string{"linguist-generated"},
1265+
Filenames: filenames,
1266+
})
1267+
if err != nil {
1268+
log.Error("CheckAttribute: %v", err)
1269+
}
1270+
for _, diffFile := range diff.Files {
1271+
attr := filename2attribute2info[diffFile.Name]["linguist-generated"]
1272+
if attr == "set" || attr == "true" {
1273+
diffFile.IsGenerated = true
1274+
}
1275+
}
1276+
12581277
if err = cmd.Wait(); err != nil {
12591278
return nil, fmt.Errorf("Wait: %v", err)
12601279
}

templates/repo/diff/box.tmpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
4949
{{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
5050
{{$isCsv := (call $.IsCsvFile $file)}}
51-
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
51+
{{$isRenderable := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
52+
{{$showFileViewToggle := or $isRenderable $file.IsGenerated}}
5253
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} mt-3" id="diff-{{.Index}}">
5354
<h4 class="diff-file-header sticky-2nd-row ui top attached normal header df ac sb">
5455
<div class="df ac">
@@ -111,13 +112,19 @@
111112
</div>
112113
{{if $showFileViewToggle}}
113114
<div id="diff-rendered-{{$i}}" class="file-body file-code {{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}">
115+
{{if $isRenderable}}
114116
<table class="chroma w-100">
115117
{{if $isImage}}
116118
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
117119
{{else}}
118120
{{template "repo/diff/csv_diff" dict "file" . "root" $}}
119121
{{end}}
120122
</table>
123+
{{else}}
124+
<div class="diff-file-body binary" style="padding: 5px 10px;">
125+
{{$.i18n.Tr "repo.diff.generated_not_shown"}}
126+
</div>
127+
{{end}}
121128
</div>
122129
{{end}}
123130
</div>

0 commit comments

Comments
 (0)