Function git_validate::tag::name
source · Expand description
Assure the given input
resemble a valid git tag name, which is returned unchanged on success.
Examples found in repository?
src/reference.rs (line 48)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
fn validate(path: &BStr, mode: Mode) -> Result<&BStr, name::Error> {
crate::tagname(path)?;
if path[0] == b'/' {
return Err(name::Error::StartsWithSlash);
}
let mut previous = 0;
let mut one_before_previous = 0;
let mut saw_slash = false;
for byte in path.iter() {
match *byte {
b'/' if previous == b'.' && one_before_previous == b'/' => return Err(name::Error::SingleDot),
b'/' if previous == b'/' => return Err(name::Error::RepeatedSlash),
_ => {}
}
if *byte == b'/' {
saw_slash = true;
}
one_before_previous = previous;
previous = *byte;
}
if let Mode::Complete = mode {
if !saw_slash && !path.iter().all(|c| c.is_ascii_uppercase() || *c == b'_') {
return Err(name::Error::SomeLowercase);
}
}
Ok(path)
}