mg/src/kind.rs
Patrick Marie 4b0902c648
Some checks failed
CI checks / Clippy (push) Failing after 30s
CI checks / Format (push) Successful in 31s
feat: write-tree
2025-02-05 09:08:18 +01:00

43 lines
1.0 KiB
Rust

use anyhow::{anyhow, Result};
#[derive(Debug)]
pub enum Kind {
Blob(bool), // 100644 or 100755
Commit, // 160000
Tree, // 040000
Symlink, // 120000
}
impl Kind {
pub fn from_mode(mode: &str) -> Result<Self> {
match mode {
"100644" => Ok(Kind::Blob(false)),
"100755" => Ok(Kind::Blob(true)),
"160000" => Ok(Kind::Commit),
"120000" => Ok(Kind::Symlink),
"040000" | "40000" => Ok(Kind::Tree),
_ => Err(anyhow!(format!("invalid mode: {}", mode))),
}
}
pub fn to_mode(&self) -> &str {
match self {
Kind::Blob(false) => "100644",
Kind::Blob(true) => "100755",
Kind::Commit => "160000",
Kind::Tree => "40000",
Kind::Symlink => "120000",
}
}
pub fn string(&self) -> &str {
match self {
Kind::Blob(_) => "blob",
Kind::Commit => "commit",
Kind::Tree => "tree",
Kind::Symlink => "symlink",
}
}
}