package main import ( "bytes" "os" "path/filepath" "strings" "unicode/utf8" ) // Restrict EOL equivalence to source/config text. Executable scripts remain byte-exact. func comparableText(path string) bool { switch strings.ToLower(filepath.Ext(path)) { case ".kt", ".kts", ".java", ".xml", ".gradle", ".properties", ".json", ".toml", ".yaml", ".yml", ".txt", ".md", ".proto", ".c", ".cc", ".cpp", ".h", ".hpp", ".cmake", ".aidl", ".pro", ".cfg", ".ini", ".csv", ".html", ".css", ".js", ".ts", ".svg": return true } switch strings.ToLower(filepath.Base(path)) { case ".gitignore", ".gitattributes", ".editorconfig", "cmakelists.txt": return true } return false } func comparisonFile(path string) (File, error) { if comparableText(path) { info, e := os.Stat(path) if e != nil { return File{}, e } if info.Size() <= 64<<20 { b, e := os.ReadFile(path) if e != nil { return File{}, e } f := File{Hash: digest(b)} if utf8.Valid(b) && !bytes.ContainsRune(b, 0) { f.TextHash = digest(bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n"))) } return f, nil } } h, e := fileDigest(path) return File{Hash: h}, e }