Skip to content

Commit

Permalink
refactor (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 9, 2022
1 parent 925d98f commit 54e882d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
26 changes: 13 additions & 13 deletions git-hash/src/owned.rs
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
2 changes: 1 addition & 1 deletion git-pack/src/multi_index/access.rs
Expand Up @@ -68,7 +68,7 @@ impl File {
}

/// TODO
pub fn lookup_prefix(&self, prefix: git_hash::Prefix) -> Option<PrefixLookupResult> {
pub fn lookup_prefix(&self, _prefix: git_hash::Prefix) -> Option<PrefixLookupResult> {
todo!()
}

Expand Down
5 changes: 3 additions & 2 deletions git-pack/tests/pack/multi_index/mod.rs
Expand Up @@ -20,14 +20,15 @@ mod access {
fn lookup_with_ambiguity() {}

#[test]
#[ignore]
fn lookup_prefix() {
let (file, _path) = multi_index();

for (idx, entry) in file.iter().enumerate() {
let hex_len = (idx % file.object_hash().len_in_hex()).min(7);
let hex_len = (idx % file.object_hash().len_in_hex()).max(7);
let hex_oid = entry.oid.to_hex_with_len(hex_len).to_string();
assert_eq!(hex_oid.len(), hex_len);
let oid_prefix = git_hash::Prefix::try_from_id(&entry.oid, hex_len);
let oid_prefix = git_hash::Prefix::try_from_id(&entry.oid, hex_len).unwrap();
let entry_index = file
.lookup_prefix(oid_prefix)
.expect("object found")
Expand Down

0 comments on commit 54e882d

Please sign in to comment.