feat: parsing single pack-file
This commit is contained in:
parent
de4c366ebb
commit
ae3c1b23af
@ -66,6 +66,11 @@ enum Command {
|
|||||||
LsIndex,
|
LsIndex,
|
||||||
/// Write the index file
|
/// Write the index file
|
||||||
WriteIndex,
|
WriteIndex,
|
||||||
|
/// Dump a Pack File
|
||||||
|
DumpPack {
|
||||||
|
/// The pack file to dump
|
||||||
|
file: PathBuf,
|
||||||
|
},
|
||||||
/// Dump Pack Files
|
/// Dump Pack Files
|
||||||
DumpPackFiles,
|
DumpPackFiles,
|
||||||
/// Dump Pack Index file
|
/// Dump Pack Index file
|
||||||
@ -130,6 +135,10 @@ fn main() -> Result<(), Error> {
|
|||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => eprintln!("Failed to dump pack files: {}", e),
|
Err(e) => eprintln!("Failed to dump pack files: {}", e),
|
||||||
},
|
},
|
||||||
|
Command::DumpPack { file } => match repo.dump_pack(&file) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => eprintln!("Failed to dump pack: {}", e),
|
||||||
|
},
|
||||||
Command::DumpPackIndexFile { pack_id } => match repo.dump_pack_index_file(&pack_id) {
|
Command::DumpPackIndexFile { pack_id } => match repo.dump_pack_index_file(&pack_id) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => eprintln!("Failed to dump pack index file: {}", e),
|
Err(e) => eprintln!("Failed to dump pack index file: {}", e),
|
||||||
|
17
src/pack.rs
17
src/pack.rs
@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufReader, Cursor, Read, Seek, SeekFrom},
|
io::{BufReader, Cursor, Read, Seek, SeekFrom},
|
||||||
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
@ -317,12 +318,8 @@ impl Repository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_pack_file(&self, pack_id: &str) -> Result<(), Error> {
|
pub fn dump_pack(&self, path: &Path) -> Result<(), Error> {
|
||||||
let file_path = self
|
let mut file = File::open(path)?;
|
||||||
.path
|
|
||||||
.join(format!(".git/objects/pack/pack-{}.pack", pack_id));
|
|
||||||
|
|
||||||
let mut file = File::open(file_path)?;
|
|
||||||
|
|
||||||
let header = parse_pack_header(&mut file)?;
|
let header = parse_pack_header(&mut file)?;
|
||||||
println!("{:?}", header);
|
println!("{:?}", header);
|
||||||
@ -350,6 +347,14 @@ impl Repository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dump_pack_file(&self, pack_id: &str) -> Result<(), Error> {
|
||||||
|
let file_path = self
|
||||||
|
.path
|
||||||
|
.join(format!(".git/objects/pack/pack-{}.pack", pack_id));
|
||||||
|
|
||||||
|
self.dump_pack(&file_path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dump_pack_index_file(&self, pack_id: &str) -> Result<(), Error> {
|
pub fn dump_pack_index_file(&self, pack_id: &str) -> Result<(), Error> {
|
||||||
let file_path = self
|
let file_path = self
|
||||||
.path
|
.path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user