aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2020-09-15 00:04:52 +0200
committerTeddy Wing2020-09-15 00:04:52 +0200
commit88864a79a0118bd48665c04fd447c5f419a23807 (patch)
treec660a1a64190001aef092c827c0dd83529d16191 /src/main.rs
parenta10a055b7b35f45cf81f31f1878154d250c98abd (diff)
downloadgit-todo-88864a79a0118bd48665c04fd447c5f419a23807.tar.bz2
src/main.rs: Print TODO lines between master...workdir
Look for TODO lines since the "master" branch. For each TODO line, print the file it's in, its line number, and the line, à la grep.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..7839c2d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,48 @@
+#![warn(rust_2018_idioms)]
+
+extern crate git2;
+
+use git2::Repository;
+
+
fn main() {
- println!("Hello, world!");
+ let repo = Repository::open(".").unwrap();
+
+ // let head = repo.head().unwrap().target().unwrap();
+ let master = repo.find_branch("master", git2::BranchType::Local).unwrap();
+ // let merge_base = repo.merge_base(head, master.get().target().unwrap()).unwrap();
+
+ let tree = master.get().peel_to_tree().unwrap();
+ let diff = repo.diff_tree_to_workdir(Some(&tree), None).unwrap();
+
+ diff.foreach(
+ &mut |_file, _progress| {
+ true
+ },
+ None,
+ None,
+ Some(
+ &mut |delta, hunk, line| {
+ // println!(
+ // "d: {:?}, h: {:?}, l: {:?}",
+ // delta,
+ // hunk,
+ // std::str::from_utf8(line.content()).unwrap(),
+ // );
+
+ let l = std::str::from_utf8(line.content()).unwrap();
+
+ if l.contains("TODO") {
+ println!(
+ "{}:{}:{}",
+ delta.new_file().path().unwrap().display(),
+ line.new_lineno().unwrap(),
+ l,
+ );
+ }
+
+ true
+ }
+ ),
+ ).unwrap();
}