From 64e2c8f6ff475f4d0e3547cbd31473e72870066b Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 6 Aug 2023 23:15:01 +0200 Subject: [PATCH] Display human-readable text instead of cryptic filemodes (#26352) (#26358) Backport #26352 Now, you don't need to be a git expert anymore to know what these numbers mean. ## Before ![grafik](https://github.com/go-gitea/gitea/assets/51889757/9a964bf6-10fd-40a6-aeb2-ac8f437f8c32) ## After ![grafik](https://github.com/go-gitea/gitea/assets/51889757/84573cb9-55b6-4dde-9866-95f71b657554) or when the mode actually changed: ![grafik](https://github.com/go-gitea/gitea/assets/51889757/0f327538-ebdc-40e7-8c99-f9e21b67f638) (cherry picked from commit 39cbca0f952ecdd1b985f20b9dd9fef4d621f99e) --- options/locales/gitea_en-US.ini | 9 +++++++++ services/gitdiff/gitdiff.go | 17 +++++++++++++++++ templates/repo/diff/box.tmpl | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/options/locales/gitea_en-US.ini b/options/locales/gitea_en-US.ini index 7e7a1b3acd..6cab7f338d 100644 --- a/options/locales/gitea_en-US.ini +++ b/options/locales/gitea_en-US.ini @@ -3491,3 +3491,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 diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 9adf3b9400..68f0e7a7ed 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -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 { diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 7d2c03fe61..8f30fcd1f1 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -110,9 +110,11 @@ {{$.locale.Tr "repo.diff.vendored"}} {{end}} {{if and $file.Mode $file.OldMode}} - {{$file.OldMode}} → {{$file.Mode}} + {{$old := $.locale.Tr ($file.ModeTranslationKey $file.OldMode)}} + {{$new := $.locale.Tr ($file.ModeTranslationKey $file.Mode)}} + {{$.locale.Tr "git.filemode.changed_filemode" $old $new}} {{else if $file.Mode}} - {{$file.Mode}} + {{$.locale.Tr ($file.ModeTranslationKey $file.Mode)}} {{end}}