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 54e882d commit 7f0efa7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion git-hash/src/owned.rs
Expand Up @@ -35,7 +35,7 @@ impl Prefix {
///
/// For instance, with `hex_len` of 7 the resulting prefix is 3.5 bytes, or 3 bytes and 4 bits
/// wide, with all other bytes and bits set to zero.
pub fn try_from_id(id: impl AsRef<oid>, hex_len: usize) -> Result<Self, prefix::Error> {
pub fn new(id: impl AsRef<oid>, hex_len: usize) -> Result<Self, prefix::Error> {
let id = id.as_ref();
if hex_len > id.kind().len_in_hex() {
Err(prefix::Error::TooLong {
Expand Down
6 changes: 3 additions & 3 deletions git-hash/tests/oid/mod.rs
Expand Up @@ -12,7 +12,7 @@ mod prefix {
let mut expected = String::from(&oid_hex[..hex_len]);
let num_of_zeros = oid.kind().len_in_hex() - hex_len;
expected.extend(std::iter::repeat('0').take(num_of_zeros));
let prefix = git_hash::Prefix::try_from_id(oid, hex_len).unwrap();
let prefix = git_hash::Prefix::new(oid, hex_len).unwrap();
assert_eq!(prefix.as_oid().to_hex().to_string(), expected, "{}", hex_len);
assert_eq!(prefix.hex_len(), hex_len);
}
Expand All @@ -22,7 +22,7 @@ mod prefix {
fn errors_if_hex_len_is_longer_than_oid_len_in_hex() {
let kind = Kind::Sha1;
assert!(matches!(
git_hash::Prefix::try_from_id(ObjectId::null(kind), kind.len_in_hex() + 1),
git_hash::Prefix::new(ObjectId::null(kind), kind.len_in_hex() + 1),
Err(git_hash::prefix::Error::TooLong { .. })
));
}
Expand All @@ -31,7 +31,7 @@ mod prefix {
fn errors_if_hex_len_is_too_short() {
let kind = Kind::Sha1;
assert!(matches!(
git_hash::Prefix::try_from_id(ObjectId::null(kind), 3),
git_hash::Prefix::new(ObjectId::null(kind), 3),
Err(git_hash::prefix::Error::TooShort { .. })
));
}
Expand Down
2 changes: 1 addition & 1 deletion git-pack/tests/pack/multi_index/mod.rs
Expand Up @@ -28,7 +28,7 @@ mod access {
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).unwrap();
let oid_prefix = git_hash::Prefix::new(&entry.oid, hex_len).unwrap();
let entry_index = file
.lookup_prefix(oid_prefix)
.expect("object found")
Expand Down

0 comments on commit 7f0efa7

Please sign in to comment.