extern crate time;
use std::io::{BufReader, BufRead};
use std::process::{Command, Stdio};
use std::str;
use std::sync::mpsc::sync_channel;
use std::thread;
mod parsing;
mod history;
mod types;
use history::*;
use parsing::*;
use types::*;
fn main() {
let (tx, rx) = sync_channel(0);
thread::spawn(move || parsing::get_history(&tx));
let paths = get_tracked_files();
let history = gather_history(&paths, &get_id, |_| true, &rx);
for (key, val) in history {
println!("{}", key);
print_history(&val);
}
}
fn get_tracked_files() -> PathSet {
let mut ret = PathSet::new();
let child = Command::new("git")
.arg("ls-files")
.stdout(Stdio::piped())
.spawn().unwrap();
let br = BufReader::new(child.stdout.unwrap());
for file in br.lines().map(|l| l.unwrap()) {
ret.insert(file);
}
ret
}
fn get_id(c: &ParsedCommit) -> String {
str::from_utf8(&Command::new("git")
.arg("log")
.arg("--oneline")
.arg("--no-walk")
.arg(c.id.to_string())
.stdout(Stdio::piped())
.output().unwrap()
.stdout).unwrap().trim().to_string()
}
fn print_history<T>(node: &Link<HistoryNode<T>>)
where T: std::fmt::Display {
let nb = node.borrow();
if let Some(ref data) = nb.data {
println!("\t{}", data);
}
if let Some(ref prev) = nb.previous {
print_history(prev)
}
}