From fc7c76aaf30385967c53bf8eb58f573a3b896788 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 23 Jan 2023 09:43:18 +0100 Subject: [PATCH] Use anyhow --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 29 +++++++++++------------------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea63105..8a646ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "anyhow" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" + [[package]] name = "arc-swap" version = "1.6.0" @@ -576,6 +582,7 @@ dependencies = [ name = "git-lot" version = "0.0.0" dependencies = [ + "anyhow", "clap", "git-repository", ] diff --git a/Cargo.toml b/Cargo.toml index c4e72fd..f6b256a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,6 @@ version = "0.0.0" edition = "2021" [dependencies] +anyhow = "1.0.68" clap = { version = "4.1.1", features = ["derive", "deprecated"] } git-repository = "0.33.0" diff --git a/src/main.rs b/src/main.rs index 7605e33..ade673b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,30 +46,23 @@ impl git_repository::traverse::tree::Visit for TreeVisitor { } } -fn print_commit(commit: &Commit) { +fn print_commit(commit: &Commit) -> anyhow::Result<()> { println!("{commit:?}"); - println!("{:?}", commit.message().unwrap()); + println!("{:?}", commit.message()?); let mut recorder = Recorder::default(); - commit - .tree() - .unwrap() - .traverse() - .breadthfirst(&mut recorder) - .unwrap(); + commit.tree()?.traverse().breadthfirst(&mut recorder)?; println!("{recorder:#?}"); println!(); + Ok(()) } -fn main() { +fn main() -> anyhow::Result<()> { let args = Args::parse(); - let repo = git_repository::discover(args.repo).unwrap(); - let commit = repo.head_commit().unwrap(); - for ancestor in commit.ancestors().all().unwrap() { - let ancestor = repo - .find_object(ancestor.unwrap()) - .unwrap() - .try_into_commit() - .unwrap(); - print_commit(&ancestor); + let repo = git_repository::discover(args.repo)?; + let commit = repo.head_commit()?; + for ancestor in commit.ancestors().all()? { + let ancestor = repo.find_object(ancestor.unwrap())?.try_into_commit()?; + print_commit(&ancestor)?; } + Ok(()) }