Skip to content

Commit 14fd012

Browse files
JakobDevdelvhlunny
authored andcommitted
Show in Web UI if file is vendored and generated (go-gitea#28620)
This simple shows in the Web UI is a file is vendored and/or generated. ![grafik](https://github.com/go-gitea/gitea/assets/15185051/bfe45fcc-cfec-4ba1-8d93-c0a262c3ae1c) ![grafik](https://github.com/go-gitea/gitea/assets/15185051/9f222a49-e7bf-4540-ba64-43dcc5767b76) --------- Co-authored-by: delvh <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent e2177e9 commit 14fd012

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,8 @@ audio_not_supported_in_browser = Your browser does not support the HTML5 'audio'
11911191
stored_lfs = Stored with Git LFS
11921192
symbolic_link = Symbolic link
11931193
executable_file = Executable File
1194+
vendored = Vendored
1195+
generated = Generated
11941196
commit_graph = Commit Graph
11951197
commit_graph.select = Select branches
11961198
commit_graph.hide_pr_refs = Hide Pull Requests

routers/web/repo/view.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
647647
}
648648
}
649649

650+
if ctx.Repo.GitRepo != nil {
651+
checker, deferable := ctx.Repo.GitRepo.CheckAttributeReader(ctx.Repo.CommitID)
652+
if checker != nil {
653+
defer deferable()
654+
attrs, err := checker.CheckPath(ctx.Repo.TreePath)
655+
if err == nil {
656+
vendored, has := attrs["linguist-vendored"]
657+
ctx.Data["IsVendored"] = has && (vendored == "set" || vendored == "true")
658+
659+
generated, has := attrs["linguist-generated"]
660+
ctx.Data["IsGenerated"] = has && (generated == "set" || generated == "true")
661+
}
662+
}
663+
}
664+
650665
if fInfo.st.IsImage() && !fInfo.st.IsSvgImage() {
651666
img, _, err := image.DecodeConfig(bytes.NewReader(buf))
652667
if err == nil {

templates/repo/file_info.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
{{ctx.Locale.Tr "repo.executable_file"}}
3131
</div>
3232
{{end}}
33+
{{if .IsVendored}}
34+
<div class="file-info-entry">
35+
{{ctx.Locale.Tr "repo.vendored"}}
36+
</div>
37+
{{end}}
38+
{{if .IsGenerated}}
39+
<div class="file-info-entry">
40+
{{ctx.Locale.Tr "repo.generated"}}
41+
</div>
42+
{{end}}
3343
{{if .ImageSize}}
3444
<div class="file-info-entry">
3545
{{.ImageSize}}

0 commit comments

Comments
 (0)