Advertisement
Guest User

Untitled

a guest
May 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. extern crate git2;
  2. extern crate rustc_serialize;
  3.  
  4. use std::collections::HashMap;
  5. use std::io;
  6. use std::io::prelude::*;
  7. use std::thread;
  8.  
  9. use git2::{Repository, Oid};
  10. use rustc_serialize::json::{self, ToJson, Json};
  11.  
  12. #[derive(RustcEncodable, Debug)]
  13. struct RepoJson {
  14. name: String,
  15. history: Vec<i64>,
  16. }
  17.  
  18. fn main() {
  19. let stdin = io::stdin();
  20. let input = stdin.lock().lines();
  21. let mut children = HashMap::new();
  22. for line in input {
  23. let name = line.unwrap();
  24. children.insert(name.clone(), thread::spawn(move || {
  25. let repo = Repository::open(name.clone()).unwrap();
  26. let mut revwalk = repo.revwalk().unwrap();
  27. let mut repo_json = RepoJson { name: name.clone(), history: vec![] };
  28. revwalk.push_head();
  29. for oid in revwalk {
  30. let time = repo.find_commit(oid).unwrap().time().seconds();
  31. repo_json.history.push(time);
  32. }
  33. repo_json
  34. }));
  35. }
  36. for (name, repo_thread) in children.iter() {
  37. let repo_json = repo_thread.join().unwrap();
  38. println!("{:?}", repo_json);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement