Traverse commits
This commit is contained in:
parent
a82db1b204
commit
3096fcc2be
3 changed files with 1387 additions and 1 deletions
1325
Cargo.lock
generated
1325
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,3 +5,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
clap = { version = "4.1.1", features = ["derive", "deprecated"] }
|
||||
git-repository = "0.33.0"
|
||||
|
|
|
|||
62
src/main.rs
62
src/main.rs
|
|
@ -1,6 +1,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
use git_repository::{traverse::tree::Recorder, Commit};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Args {
|
||||
|
|
@ -9,7 +10,66 @@ struct Args {
|
|||
repo: PathBuf,
|
||||
}
|
||||
|
||||
struct TreeVisitor;
|
||||
|
||||
impl git_repository::traverse::tree::Visit for TreeVisitor {
|
||||
fn pop_front_tracked_path_and_set_current(&mut self) {
|
||||
println!("pop_front_tracked_path_and_set_current");
|
||||
}
|
||||
|
||||
fn push_back_tracked_path_component(&mut self, component: &git_repository::bstr::BStr) {
|
||||
println!("push_back_tracked_path_component {component:?}");
|
||||
}
|
||||
|
||||
fn push_path_component(&mut self, component: &git_repository::bstr::BStr) {
|
||||
println!("push_path_component {component:?}");
|
||||
}
|
||||
|
||||
fn pop_path_component(&mut self) {
|
||||
println!("pop_path_component");
|
||||
}
|
||||
|
||||
fn visit_tree(
|
||||
&mut self,
|
||||
entry: &git_repository::objs::tree::EntryRef<'_>,
|
||||
) -> git_repository::traverse::tree::visit::Action {
|
||||
println!("visit_tree {entry:?}");
|
||||
git_repository::traverse::tree::visit::Action::Continue
|
||||
}
|
||||
|
||||
fn visit_nontree(
|
||||
&mut self,
|
||||
entry: &git_repository::objs::tree::EntryRef<'_>,
|
||||
) -> git_repository::traverse::tree::visit::Action {
|
||||
println!("visit_nontree {entry:?}");
|
||||
git_repository::traverse::tree::visit::Action::Continue
|
||||
}
|
||||
}
|
||||
|
||||
fn print_commit(commit: &Commit) {
|
||||
println!("{commit:?}");
|
||||
println!("{:?}", commit.message().unwrap());
|
||||
let mut recorder = Recorder::default();
|
||||
commit
|
||||
.tree()
|
||||
.unwrap()
|
||||
.traverse()
|
||||
.breadthfirst(&mut recorder)
|
||||
.unwrap();
|
||||
println!("{recorder:#?}");
|
||||
println!();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
println!("Args: {args:#?}");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue