History

refactor (#427)

Sebastian Thiel committed 4 years ago

Commit 2e498311 parent 16945ed1 file · +9 −9Browse files

Unified · Split

git-revision/src/spec.rs+9−9
@@ -94,15 +94,15 @@ pub mod parse { · 93 unmodified lines
9494 if name.is_empty() && sep == Some(b'@') {
9595 delegate.set_ref("HEAD".into()).ok_or(Error::Delegate)?;
9696 } else {
97− if consecutive_hex_chars.unwrap_or(0) >= git_hash::Prefix::MIN_HEX_LEN {
98− git_hash::Prefix::from_hex(name.to_str().expect("hexadecimal only"))
99− .ok()
100− .and_then(|prefix| delegate.set_prefix(prefix))
101− .or_else(|| delegate.set_ref(name))
102− } else {
103− delegate.set_ref(name)
104− }
105− .ok_or(Error::Delegate)?;
97+ (consecutive_hex_chars.unwrap_or(0) >= git_hash::Prefix::MIN_HEX_LEN)
98+ .then(|| {
99+ git_hash::Prefix::from_hex(name.to_str().expect("hexadecimal only"))
100+ .ok()
101+ .and_then(|prefix| delegate.set_prefix(prefix))
102+ })
103+ .flatten()
104+ .or_else(|| delegate.set_ref(name))
105+ .ok_or(Error::Delegate)?;
106106 }
107107
108108 let past_sep = input[sep_pos.map(|pos| pos + 1).unwrap_or(input.len())..].as_bstr();