Skip to content

Instantly share code, notes, and snippets.

@bmcorser
Created May 29, 2016 07:40
Show Gist options
  • Save bmcorser/599c92e06da0bedefc0d4c5bb1e837e6 to your computer and use it in GitHub Desktop.
Save bmcorser/599c92e06da0bedefc0d4c5bb1e837e6 to your computer and use it in GitHub Desktop.
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);
}
}
@bmcorser
Copy link
Author

src/main.rs:37:25: 37:36 error: cannot move out of borrowed content [E0507]
src/main.rs:37         let repo_json = repo_thread.join().unwrap();
                                       ^~~~~~~~~~~
src/main.rs:37:25: 37:36 help: run `rustc --explain E0507` to see a detailed explanation
error: aborting due to previous error
error: Could not compile `repo-commits`.

To learn more, run the command again with --verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment