Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display human-readable text instead of cryptic filemodes (#26352) #26358

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Display human-readable text instead of cryptic filemodes (#26352)
delvh committed Aug 6, 2023
commit 10ac9caf93a9a3769ad585e3dbcaa699c77685b3
9 changes: 9 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
@@ -3474,3 +3474,12 @@ need_approval_desc = Need approval to run workflows for fork pull request.
type-1.display_name = Individual Project
type-2.display_name = Repository Project
type-3.display_name = Organization Project

[git.filemode]
changed_filemode = %[1]s → %[2]s
# Ordered by git filemode value, ascending. E.g. directory has "040000", normal file has "100644", …
directory = Directory
normal_file = Normal file
executable_file = Executable file
symbolic_link = Symbolic link
submodule = Submodule
17 changes: 17 additions & 0 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
@@ -427,6 +427,23 @@ func (diffFile *DiffFile) ShouldBeHidden() bool {
return diffFile.IsGenerated || diffFile.IsViewed
}

func (diffFile *DiffFile) ModeTranslationKey(mode string) string {
switch mode {
case "040000":
return "git.filemode.directory"
case "100644":
return "git.filemode.normal_file"
case "100755":
return "git.filemode.executable_file"
case "120000":
return "git.filemode.symbolic_link"
case "160000":
return "git.filemode.submodule"
default:
return mode
}
}

func getCommitFileLineCount(commit *git.Commit, filePath string) int {
blob, err := commit.GetBlobByPath(filePath)
if err != nil {
6 changes: 4 additions & 2 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
@@ -110,9 +110,11 @@
<span class="ui label">{{$.locale.Tr "repo.diff.vendored"}}</span>
{{end}}
{{if and $file.Mode $file.OldMode}}
<span class="gt-ml-4 gt-mono">{{$file.OldMode}} &rarr; {{$file.Mode}}</span>
{{$old := $.locale.Tr ($file.ModeTranslationKey $file.OldMode)}}
{{$new := $.locale.Tr ($file.ModeTranslationKey $file.Mode)}}
<span class="gt-ml-4 gt-mono">{{$.locale.Tr "git.filemode.changed_filemode" $old $new}}</span>
{{else if $file.Mode}}
<span class="gt-ml-4 gt-mono">{{$file.Mode}}</span>
<span class="gt-ml-4 gt-mono">{{$.locale.Tr ($file.ModeTranslationKey $file.Mode)}}</span>
{{end}}
</div>
<div class="diff-file-header-actions gt-df gt-ac gt-gap-2 gt-fw">