mirror of
https://github.com/go-gitea/gitea.git
synced 2026-02-07 09:49:41 +09: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:
@@ -46,8 +46,8 @@ func parseLsTreeLine(line []byte) (*LsTreeEntry, error) {
|
||||
entry.Size = optional.Some(size)
|
||||
}
|
||||
|
||||
entry.EntryMode, err = ParseEntryMode(string(entryMode))
|
||||
if err != nil || entry.EntryMode == EntryModeNoEntry {
|
||||
entry.EntryMode = ParseEntryMode(string(entryMode))
|
||||
if entry.EntryMode == EntryModeNoEntry {
|
||||
return nil, fmt.Errorf("invalid ls-tree output (invalid mode): %q, err: %w", line, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -55,21 +54,38 @@ func (e EntryMode) IsExecutable() bool {
|
||||
return e == EntryModeExec
|
||||
}
|
||||
|
||||
func ParseEntryMode(mode string) (EntryMode, error) {
|
||||
func ParseEntryMode(mode string) EntryMode {
|
||||
switch mode {
|
||||
case "000000":
|
||||
return EntryModeNoEntry, nil
|
||||
return EntryModeNoEntry
|
||||
case "100644":
|
||||
return EntryModeBlob, nil
|
||||
return EntryModeBlob
|
||||
case "100755":
|
||||
return EntryModeExec, nil
|
||||
return EntryModeExec
|
||||
case "120000":
|
||||
return EntryModeSymlink, nil
|
||||
return EntryModeSymlink
|
||||
case "160000":
|
||||
return EntryModeCommit, nil
|
||||
case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons
|
||||
return EntryModeTree, nil
|
||||
return EntryModeCommit
|
||||
case "040000":
|
||||
return EntryModeTree
|
||||
default:
|
||||
return 0, fmt.Errorf("unparsable entry mode: %s", mode)
|
||||
// git uses 040000 for tree object, but some users may get 040755 from non-standard git implementations
|
||||
m, _ := strconv.ParseInt(mode, 8, 32)
|
||||
modeInt := EntryMode(m)
|
||||
switch modeInt & 0o770000 {
|
||||
case 0o040000:
|
||||
return EntryModeTree
|
||||
case 0o160000:
|
||||
return EntryModeCommit
|
||||
case 0o120000:
|
||||
return EntryModeSymlink
|
||||
case 0o100000:
|
||||
if modeInt&0o777 == 0o755 {
|
||||
return EntryModeExec
|
||||
}
|
||||
return EntryModeBlob
|
||||
default:
|
||||
return EntryModeNoEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,3 +27,30 @@ func TestEntriesCustomSort(t *testing.T) {
|
||||
entries.CustomSort(strings.Compare)
|
||||
assert.Equal(t, expected, entries)
|
||||
}
|
||||
|
||||
func TestParseEntryMode(t *testing.T) {
|
||||
tests := []struct {
|
||||
modeStr string
|
||||
expectMod EntryMode
|
||||
}{
|
||||
{"000000", EntryModeNoEntry},
|
||||
{"000755", EntryModeNoEntry},
|
||||
|
||||
{"100644", EntryModeBlob},
|
||||
{"100755", EntryModeExec},
|
||||
|
||||
{"120000", EntryModeSymlink},
|
||||
{"120755", EntryModeSymlink},
|
||||
{"160000", EntryModeCommit},
|
||||
{"160755", EntryModeCommit},
|
||||
|
||||
{"040000", EntryModeTree},
|
||||
{"040755", EntryModeTree},
|
||||
|
||||
{"777777", EntryModeNoEntry}, // invalid mode
|
||||
}
|
||||
for _, test := range tests {
|
||||
mod := ParseEntryMode(test.modeStr)
|
||||
assert.Equal(t, test.expectMod, mod, "modeStr: %s", test.modeStr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user