Skip to main content

Module event_path

Module event_path 

Source
Expand description

A pathname as events report it: text, plus base64 pathBytes when it is not UTF-8. What: A repository path as an event reports it: readable text, and the exact bytes as well when those bytes are not UTF-8. Why: Git allows any bytes in a file name, and a JSON string can hold only text. An event keeps path as text with replacement characters, so every existing reader works unchanged, and adds an optional pathBytes field, base64 encoded, only for a name that is not UTF-8, so a reader that needs the file can still find it. This is option C of doc/planning/cli-git-rust-open-decisions.md, section “Non-UTF-8 paths in events and journals”, which the owner adopted.

In TS you’d write (pseudocode):

// const path = eventPath(bytes); line.path = path.text; if (path.exact) line.pathBytes = base64(path.exact);

Structs§

EventPath
What: One path as events report it. The fields are private, so the only ways to build one are the two constructors, and exact is present exactly when the bytes were not UTF-8. #[derive(...)] generates cloning, debug printing and ==. Why: A reader must be able to rely on “no pathBytes means path is the exact name”.

Functions§

base64_decode_standard
What: Decode standard padded base64 (RFC 4648 section 4) into bytes, or nothing when the text is not exactly what base64_standard would print for some bytes. Why: A journal that holds the exact bytes of a name that is not UTF-8 is read back by the wrapper; a text that decodes in more than one way (stray padding, non-zero spare bits) is a damaged record, not a name.
base64_standard
What: Encode bytes as standard base64 with = padding (RFC 4648 section 4). Why: pathBytes carries exact pathname bytes inside a JSON string. Base64 is what ripgrep’s JSON output uses for a path that is not UTF-8 and what Go’s JSON encoding uses for bytes; it is unmistakably not a name, so no reader uses it as one by accident. Every three input bytes become four characters; a final group of one or two bytes is padded to four characters with =.