Created
May 29, 2016 07:40
-
-
Save bmcorser/599c92e06da0bedefc0d4c5bb1e837e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate git2; | |
extern crate rustc_serialize; | |
use std::collections::HashMap; | |
use std::io; | |
use std::io::prelude::*; | |
use std::thread; | |
use git2::{Repository, Oid}; | |
use rustc_serialize::json::{self, ToJson, Json}; | |
#[derive(RustcEncodable, Debug)] | |
struct RepoJson { | |
name: String, | |
history: Vec<i64>, | |
} | |
fn main() { | |
let stdin = io::stdin(); | |
let input = stdin.lock().lines(); | |
let mut children = HashMap::new(); | |
for line in input { | |
let name = line.unwrap(); | |
children.insert(name.clone(), thread::spawn(move || { | |
let repo = Repository::open(name.clone()).unwrap(); | |
let mut revwalk = repo.revwalk().unwrap(); | |
let mut repo_json = RepoJson { name: name.clone(), history: vec![] }; | |
revwalk.push_head(); | |
for oid in revwalk { | |
let time = repo.find_commit(oid).unwrap().time().seconds(); | |
repo_json.history.push(time); | |
} | |
repo_json | |
})); | |
} | |
for (name, repo_thread) in children.iter() { | |
let repo_json = repo_thread.join().unwrap(); | |
println!("{:?}", repo_json); | |
} | |
} |
Author
bmcorser
commented
May 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment