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",
]
[[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",
]

View file

@ -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"

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.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(())
}