MCPcopy Create free account
hub / github.com/antonmedv/gitmal / ParseFileMode

Function ParseFileMode

pkg/git/utils.go:11–25  ·  view source on GitHub ↗

ParseFileMode converts a git-style file mode (e.g. "100644") into a human-readable string like "rw-r--r--".

(modeStr string)

Source from the content-addressed store, hash-verified

9// ParseFileMode converts a git-style file mode (e.g. "100644")
10// into a human-readable string like "rw-r--r--".
11func ParseFileMode(modeStr string) (string, error) {
12 // Git modes are typically 6 digits. The last 3 represent permissions.
13 // e.g. 100644 → 644
14 if len(modeStr) < 3 {
15 return "", fmt.Errorf("invalid mode: %s", modeStr)
16 }
17
18 permStr := modeStr[len(modeStr)-3:]
19 permVal, err := strconv.Atoi(permStr)
20 if err != nil {
21 return "", err
22 }
23
24 return numericPermToLetters(permVal), nil
25}
26
27func numericPermToLetters(perm int) string {
28 // Map each octal digit to rwx letters

Callers 3

TestParseFileModeFunction · 0.92
TestParseFileModeInvalidFunction · 0.92
FilesFunction · 0.85

Calls 2

numericPermToLettersFunction · 0.85
ErrorfMethod · 0.80

Tested by 2

TestParseFileModeFunction · 0.74
TestParseFileModeInvalidFunction · 0.74