Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libra/src/utils/client_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use mercury::internal::pack::Pack;
use mercury::errors::GitError;
use mercury::hash::SHA1;
use mercury::internal::object::types::ObjectType;
use mercury::utils::read_sha1;

use crate::command;
use crate::utils::util;

#[derive(Default)]
pub struct ClientStorage {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl ClientStorage {
let mut objs = Vec::new();
for _ in 0..fanout[255] {
let _offset = idx_file.read_u32::<BigEndian>()?;
let hash = util::read_sha1(&mut idx_file)?;
let hash = read_sha1(&mut idx_file)?;

objs.push(hash);
}
Expand All @@ -283,7 +283,7 @@ impl ClientStorage {
idx_file.seek(io::SeekFrom::Start((FANOUT + 24 * start) as u64))?;
for _ in start..end {
let offset = idx_file.read_u32::<BigEndian>()?;
let hash = util::read_sha1(&mut idx_file)?;
let hash = read_sha1(&mut idx_file)?;

if &hash == obj_id {
return Ok(Some(offset as u64));
Expand Down
6 changes: 0 additions & 6 deletions libra/src/utils/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,6 @@ pub fn get_repo_name_from_url(mut url: &str) -> Option<&str> {
Some(&url[repo_start..repo_end])
}

pub fn read_sha1(file: &mut impl Read) -> io::Result<SHA1> {
let mut buf = [0; 20];
file.read_exact(&mut buf)?;
Ok(SHA1::from_bytes(&buf))
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
21 changes: 1 addition & 20 deletions mercury/src/internal/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};

use crate::utils;
use crate::errors::GitError;
use crate::hash::SHA1;
use crate::internal::pack::wrapper::Wrapper;
Expand Down Expand Up @@ -432,26 +433,6 @@ impl Index {
}
}

mod utils {
use std::io;
use std::io::Read;
use crate::hash::SHA1;

pub const SHA1_SIZE: usize = 20;

pub fn read_bytes(file: &mut impl Read, len: usize) -> io::Result<Vec<u8>> {
let mut buf = vec![0; len];
file.read_exact(&mut buf)?;
Ok(buf)
}

pub fn read_sha1(file: &mut impl Read) -> io::Result<SHA1> {
let mut buf = [0; 20];
file.read_exact(&mut buf)?;
Ok(SHA1::from_bytes(&buf))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions mercury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static GLOBAL: MiMalloc = MiMalloc;
pub mod internal;
pub mod hash;
pub mod errors;
pub mod utils;

#[cfg(test)]
mod tests {}
18 changes: 18 additions & 0 deletions mercury/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::io;
use std::io::Read;

use crate::hash::SHA1;

pub const SHA1_SIZE: usize = 20;

pub fn read_bytes(file: &mut impl Read, len: usize) -> io::Result<Vec<u8>> {
let mut buf = vec![0; len];
file.read_exact(&mut buf)?;
Ok(buf)
}

pub fn read_sha1(file: &mut impl Read) -> io::Result<SHA1> {
let mut buf = [0; 20];
file.read_exact(&mut buf)?;
Ok(SHA1::from_bytes(&buf))
}