//! vocabulary shared by the projection modules, lifted from knot-xrpc/src/wire.rs. //! single definition point: `out`, `patchtext`, `bounded`, and `read_model` all render //! the same upstream shapes. use knot_git::EntryKind; // Origin: knot-xrpc/src/wire.rs: entry_mode_decimal pub fn entry_mode_decimal(kind: EntryKind) -> u32 { match kind { EntryKind::Tree => 0o040000, EntryKind::Blob => 0o100644, EntryKind::BlobExecutable => 0o100755, EntryKind::Link => 0o120000, EntryKind::Commit => 0o160000, } } // Origin: knot-xrpc/src/wire.rs: entry_mode_octal pub fn entry_mode_octal(kind: EntryKind) -> String { format!("{:06o}", entry_mode_decimal(kind)) } // Origin: knot-xrpc/src/wire.rs: fold_subject pub fn fold_subject(message: &str) -> String { message .split("\n\n") .next() .unwrap_or_default() .lines() .map(str::trim_end) .filter(|line| !line.is_empty()) .collect::>() .join(" ") } // Origin: knot-xrpc/src/wire.rs: message_body pub fn message_body(message: &str) -> String { message .split_once("\n\n") .map(|(_, body)| body.trim_matches('\n')) .unwrap_or_default() .to_string() } // Origin: knot-xrpc/src/wire.rs: rfc2822 pub fn rfc2822(seconds: i64, offset_seconds: i32) -> String { zoned(seconds, offset_seconds).to_rfc2822() } // Origin: knot-xrpc/src/wire.rs: rfc3339 pub fn rfc3339(seconds: i64, offset_seconds: i32) -> String { zoned(seconds, offset_seconds).to_rfc3339_opts(chrono::SecondsFormat::Secs, true) } fn zoned(seconds: i64, offset_seconds: i32) -> chrono::DateTime { let offset = chrono::FixedOffset::east_opt(offset_seconds) .unwrap_or_else(|| chrono::FixedOffset::east_opt(0).expect("zero offset is valid")); chrono::DateTime::from_timestamp(seconds, 0) .unwrap_or_default() .with_timezone(&offset) }