Use anyhow

This commit is contained in:
Joscha 2023-01-23 09:43:18 +01:00
parent 3096fcc2be
commit fc7c76aaf3
3 changed files with 19 additions and 18 deletions

7
Cargo.lock generated
View file

@ -20,6 +20,12 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "anyhow"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "1.6.0" version = "1.6.0"
@ -576,6 +582,7 @@ dependencies = [
name = "git-lot" name = "git-lot"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"anyhow",
"clap", "clap",
"git-repository", "git-repository",
] ]

View file

@ -4,5 +4,6 @@ version = "0.0.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.68"
clap = { version = "4.1.1", features = ["derive", "deprecated"] } clap = { version = "4.1.1", features = ["derive", "deprecated"] }
git-repository = "0.33.0" git-repository = "0.33.0"

View file

@ -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:?}");
println!("{:?}", commit.message().unwrap()); println!("{:?}", commit.message()?);
let mut recorder = Recorder::default(); let mut recorder = Recorder::default();
commit commit.tree()?.traverse().breadthfirst(&mut recorder)?;
.tree()
.unwrap()
.traverse()
.breadthfirst(&mut recorder)
.unwrap();
println!("{recorder:#?}"); println!("{recorder:#?}");
println!(); println!();
Ok(())
} }
fn main() { fn main() -> anyhow::Result<()> {
let args = Args::parse(); let args = Args::parse();
let repo = git_repository::discover(args.repo).unwrap(); let repo = git_repository::discover(args.repo)?;
let commit = repo.head_commit().unwrap(); let commit = repo.head_commit()?;
for ancestor in commit.ancestors().all().unwrap() { for ancestor in commit.ancestors().all()? {
let ancestor = repo let ancestor = repo.find_object(ancestor.unwrap())?.try_into_commit()?;
.find_object(ancestor.unwrap()) print_commit(&ancestor)?;
.unwrap()
.try_into_commit()
.unwrap();
print_commit(&ancestor);
} }
Ok(())
} }