Skip to content

Commit

Permalink
refactor (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 8, 2022
1 parent 925d98f commit 8251bc5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions git-hash/src/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod prefix {
use quick_error::quick_error;

quick_error! {
/// TODO:
/// The error returned by [Prefix::try_from_id()][super::Prefix::try_from_id()].
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
Expand All @@ -38,23 +38,23 @@ impl Prefix {
pub fn try_from_id(id: impl AsRef<oid>, hex_len: usize) -> Result<Self, prefix::Error> {
let id = id.as_ref();
if hex_len > id.kind().len_in_hex() {
return Err(prefix::Error::TooLong {
Err(prefix::Error::TooLong {
object_kind: id.kind(),
hex_len,
});
})
} else if hex_len < 4 {
return Err(prefix::Error::TooShort { hex_len });
}
Err(prefix::Error::TooShort { hex_len })
} else {
let mut prefix = ObjectId::null(id.kind());
let b = prefix.as_mut_slice();
let copy_len = (hex_len + 1) / 2;
b[..copy_len].copy_from_slice(&id.as_bytes()[..copy_len]);
if hex_len % 2 == 1 {
b[hex_len / 2] &= 0xf0;
}

let mut prefix = ObjectId::null(id.kind());
let b = prefix.as_mut_slice();
let copy_len = (hex_len + 1) / 2;
b[..copy_len].copy_from_slice(&id.as_bytes()[..copy_len]);
if hex_len % 2 == 1 {
b[hex_len / 2] &= 0xf0;
Ok(Prefix { bytes: prefix, hex_len })
}

Ok(Prefix { bytes: prefix, hex_len })
}

/// Returns the prefix as object id.
Expand Down

0 comments on commit 8251bc5

Please sign in to comment.