aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: 1b9689a8cd6eeae6facd630845ad9b287c5f8af9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![warn(rust_2018_idioms)]

use std::io::Write;

use git2::Repository;


pub fn write_since<W: Write>(write_to: &mut W) {
    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(),
                // );

                if let Some(line_number) = line.new_lineno() {
                    let l = std::str::from_utf8(line.content()).unwrap();

                    if l.contains("TODO") {
                        write!(
                            write_to,
                            "{}:{}:{}",
                            delta.new_file().path().unwrap().display(),
                            line_number,
                            l,
                        ).unwrap();
                    }
                }

                true
            }
        ),
    ).unwrap();
}