MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_ref_name

Function validate_ref_name

atomic-core/src/pristine/ref_mapping.rs:336–357  ·  view source on GitHub ↗

A mapped ref name: well-formed Git reference name under `refs/` (git-check-ref-format's exclusions, simplified to the durable subset).

(value: Option<&str>)

Source from the content-addressed store, hash-verified

334/// A mapped ref name: well-formed Git reference name under `refs/`
335/// (git-check-ref-format's exclusions, simplified to the durable subset).
336fn validate_ref_name(value: Option<&str>) -> PristineResult<()> {
337 let Some(value) = value else {
338 return Ok(());
339 };
340 let forbidden = [b'~', b'^', b':', b'?', b'*', b'[', b'\\', 0x7f];
341 let well_formed = value.starts_with("refs/")
342 && !value.ends_with('/')
343 && !value.ends_with(".")
344 && !value.contains("..")
345 && !value.contains("//")
346 && !value.contains("@{")
347 && !value.ends_with(".lock")
348 && value
349 .bytes()
350 .all(|b| b.is_ascii_graphic() && !forbidden.contains(&b));
351 if !well_formed {
352 return Err(PristineError::Serialization {
353 message: format!("ref mapping ref name is not a well-formed Git reference: {value:?}"),
354 });
355 }
356 Ok(())
357}
358
359fn encode_len_prefixed(bytes: &mut Vec<u8>, value: &[u8]) -> PristineResult<()> {
360 if value.len() > u16::MAX as usize {

Callers 2

encodeMethod · 0.85
decodeMethod · 0.85

Calls 3

containsMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45

Tested by

no test coverage detected