From ae3c1b23af2caa1dce6eda9ceedb20566635e0a0 Mon Sep 17 00:00:00 2001 From: Patrick Marie Date: Tue, 11 Feb 2025 19:23:08 +0100 Subject: [PATCH] feat: parsing single pack-file --- src/main.rs | 9 +++++++++ src/pack.rs | 17 +++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index b4c759c..c425294 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,6 +66,11 @@ enum Command { LsIndex, /// Write the index file WriteIndex, + /// Dump a Pack File + DumpPack { + /// The pack file to dump + file: PathBuf, + }, /// Dump Pack Files DumpPackFiles, /// Dump Pack Index file @@ -130,6 +135,10 @@ fn main() -> Result<(), Error> { Ok(_) => (), 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) { Ok(_) => (), Err(e) => eprintln!("Failed to dump pack index file: {}", e), diff --git a/src/pack.rs b/src/pack.rs index fe914e0..b540db6 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -1,6 +1,7 @@ use std::{ fs::File, io::{BufReader, Cursor, Read, Seek, SeekFrom}, + path::Path, }; use anyhow::Error; @@ -317,12 +318,8 @@ impl Repository { 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)); - - let mut file = File::open(file_path)?; + pub fn dump_pack(&self, path: &Path) -> Result<(), Error> { + let mut file = File::open(path)?; let header = parse_pack_header(&mut file)?; println!("{:?}", header); @@ -350,6 +347,14 @@ impl Repository { 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> { let file_path = self .path