mirror of
https://github.com/go-gitea/gitea
synced 2026-02-03 08:50:36 +00:00
Improve diff file headers (#36215)
- reduce file name font size from 15px to 14px - fix labels and buttons being cut off when their size is constrained - change labels from monospace to sans-serif font - move diff stats to right and change them from sum of changes to +/- - change filemode to label and change text to match other labels --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -166,16 +166,6 @@ func parseGitDiffTreeLine(line string) (*DiffTreeRecord, error) {
|
||||
return nil, fmt.Errorf("unparsable output for diff-tree --raw: `%s`, expected 5 space delimited values got %d)", line, len(fields))
|
||||
}
|
||||
|
||||
baseMode, err := git.ParseEntryMode(fields[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headMode, err := git.ParseEntryMode(fields[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
baseBlobID := fields[2]
|
||||
headBlobID := fields[3]
|
||||
|
||||
@@ -201,8 +191,8 @@ func parseGitDiffTreeLine(line string) (*DiffTreeRecord, error) {
|
||||
return &DiffTreeRecord{
|
||||
Status: status,
|
||||
Score: score,
|
||||
BaseMode: baseMode,
|
||||
HeadMode: headMode,
|
||||
BaseMode: git.ParseEntryMode(fields[0]),
|
||||
HeadMode: git.ParseEntryMode(fields[1]),
|
||||
BaseBlobID: baseBlobID,
|
||||
HeadBlobID: headBlobID,
|
||||
BasePath: basePath,
|
||||
|
||||
+46
-31
@@ -399,20 +399,20 @@ type DiffFile struct {
|
||||
isAmbiguous bool
|
||||
|
||||
// basic fields (parsed from diff result)
|
||||
Name string
|
||||
NameHash string
|
||||
OldName string
|
||||
Addition int
|
||||
Deletion int
|
||||
Type DiffFileType
|
||||
Mode string
|
||||
OldMode string
|
||||
IsCreated bool
|
||||
IsDeleted bool
|
||||
IsBin bool
|
||||
IsLFSFile bool
|
||||
IsRenamed bool
|
||||
IsSubmodule bool
|
||||
Name string
|
||||
NameHash string
|
||||
OldName string
|
||||
Addition int
|
||||
Deletion int
|
||||
Type DiffFileType
|
||||
EntryMode string
|
||||
OldEntryMode string
|
||||
IsCreated bool
|
||||
IsDeleted bool
|
||||
IsBin bool
|
||||
IsLFSFile bool
|
||||
IsRenamed bool
|
||||
IsSubmodule bool
|
||||
// basic fields but for render purpose only
|
||||
Sections []*DiffSection
|
||||
IsIncomplete bool
|
||||
@@ -501,21 +501,36 @@ 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 (diffFile *DiffFile) TranslateDiffEntryMode(locale translation.Locale) string {
|
||||
entryModeTr := func(mode string) string {
|
||||
entryMode := git.ParseEntryMode(mode)
|
||||
switch {
|
||||
case entryMode.IsDir():
|
||||
return locale.TrString("git.filemode.directory")
|
||||
case entryMode.IsRegular():
|
||||
return locale.TrString("git.filemode.normal_file")
|
||||
case entryMode.IsExecutable():
|
||||
return locale.TrString("git.filemode.executable_file")
|
||||
case entryMode.IsLink():
|
||||
return locale.TrString("git.filemode.symbolic_link")
|
||||
case entryMode.IsSubModule():
|
||||
return locale.TrString("git.filemode.submodule")
|
||||
default:
|
||||
return mode
|
||||
}
|
||||
}
|
||||
|
||||
if diffFile.EntryMode != "" && diffFile.OldEntryMode != "" {
|
||||
oldMode := entryModeTr(diffFile.OldEntryMode)
|
||||
newMode := entryModeTr(diffFile.EntryMode)
|
||||
return locale.TrString("git.filemode.changed_filemode", oldMode, newMode)
|
||||
}
|
||||
if diffFile.EntryMode != "" {
|
||||
if entryMode := git.ParseEntryMode(diffFile.EntryMode); !entryMode.IsRegular() {
|
||||
return entryModeTr(diffFile.EntryMode)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type limitByteWriter struct {
|
||||
@@ -695,10 +710,10 @@ parsingLoop:
|
||||
strings.HasPrefix(line, "new mode "):
|
||||
|
||||
if strings.HasPrefix(line, "old mode ") {
|
||||
curFile.OldMode = prepareValue(line, "old mode ")
|
||||
curFile.OldEntryMode = prepareValue(line, "old mode ")
|
||||
}
|
||||
if strings.HasPrefix(line, "new mode ") {
|
||||
curFile.Mode = prepareValue(line, "new mode ")
|
||||
curFile.EntryMode = prepareValue(line, "new mode ")
|
||||
}
|
||||
if strings.HasSuffix(line, " 160000\n") {
|
||||
curFile.IsSubmodule, curFile.SubmoduleDiffInfo = true, &SubmoduleDiffInfo{}
|
||||
@@ -733,7 +748,7 @@ parsingLoop:
|
||||
curFile.Type = DiffFileAdd
|
||||
curFile.IsCreated = true
|
||||
if strings.HasPrefix(line, "new file mode ") {
|
||||
curFile.Mode = prepareValue(line, "new file mode ")
|
||||
curFile.EntryMode = prepareValue(line, "new file mode ")
|
||||
}
|
||||
if strings.HasSuffix(line, " 160000\n") {
|
||||
curFile.IsSubmodule, curFile.SubmoduleDiffInfo = true, &SubmoduleDiffInfo{}
|
||||
|
||||
Reference in New Issue
Block a user