gitdataai/libs/git/ssh/ref_update.rs
ZhenYi 3b17a0493f refactor(git/ssh): extract helper functions into dedicated modules
Move RefUpdate, GitService, branch_protection check, and forward
function from handle.rs into separate modules.
2026-05-11 17:05:30 +08:00

38 lines
1.2 KiB
Rust

#[derive(Clone, Debug)]
pub struct RefUpdate {
pub name: String,
pub old_oid: String,
pub new_oid: String,
}
impl RefUpdate {
/// Parse git reference update commands from SSH protocol text.
/// Format: "<old-oid> <new-oid> <ref-name>\n"
pub fn parse_ref_updates(data: &[u8]) -> Result<Vec<Self>, String> {
let text = String::from_utf8_lossy(data);
let mut refs = Vec::new();
for line in text.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') || line.starts_with("PACK") {
continue;
}
let mut parts = line.split_whitespace();
let old_oid = parts.next().map(|s| s.to_string()).unwrap_or_default();
let new_oid = parts.next().map(|s| s.to_string()).unwrap_or_default();
let name = parts
.next()
.unwrap_or("")
.trim_start_matches('\0')
.to_string();
if !name.is_empty() {
refs.push(RefUpdate {
old_oid,
new_oid,
name,
});
}
}
Ok(refs)
}
}