M Cargo.lock => Cargo.lock +0 -1
@@ 645,7 645,6 @@ dependencies = [
"lazy_static",
"memchr",
"mio",
- "num_cpus",
"pin-project-lite",
"slab",
]
M Cargo.toml => Cargo.toml +1 -1
@@ 16,7 16,7 @@ lazy_static = "1.4.0"
rayon = { version = "1.3.0", optional = true }
hyper = { version = "0.13.5", optional = true }
-tokio = { version = "*", optional = true, features = ["rt-threaded"] } # hyper provides version for tokio
+tokio = { version = "*", optional = true, features = ["rt-core", "blocking"] } # hyper provides version for tokio
[features]
default = ["rayon"]
M src/commits.rs => src/commits.rs +7 -0
@@ 11,6 11,7 @@ use crate::{log, ProjectMetadata};
pub fn find_dates(
author: Option<&String>,
+ pull: bool,
repos: &HashSet<ProjectMetadata>,
) -> Vec<(DateTime<Utc>, ProjectMetadata)> {
let commit_count = AtomicU32::new(0);
@@ 24,11 25,17 @@ pub fn find_dates(
let commit_dates = repo_iter.map(|repo| {
let mut commit_dates: Vec<(DateTime<Utc>, ProjectMetadata)> = Vec::new();
let path = &repo.path;
+
+ if pull {
+ run_git(&path, &["pull", "--all"]);
+ }
+
let mut args = vec!["log", "--all", "--format=format:%ai", "--date=iso8601"];
if let Some(author_flag) = &author_flag {
args.push(author_flag);
}
let commits = run_git(&path, &args);
+
for date in commits.lines().filter_map(|date| date.parse().ok()) {
let count = commit_count.fetch_add(1, Ordering::Relaxed) + 1;
log::verbose_println(&format!("commits accounted for {}\r", count), true);
M src/main.rs => src/main.rs +5 -1
@@ 66,6 66,10 @@ pub struct GenerationData {
/// repositories you want to include
#[structopt(short, long)]
input: Vec<PathBuf>,
+ /// Should the git repositories be pulled before analysis
+ /// (warning: this will generally increase latency a lot)
+ #[structopt(long)]
+ pull: bool,
}
#[derive(StructOpt, Clone, Default)]
@@ 218,6 222,6 @@ fn main() {
pub fn generate_years(gen: &GenerationData) -> Vec<Year> {
let repos = find_repositories::from_paths(&gen.input, gen.depth);
- let commit_dates = commits::find_dates(gen.author.as_ref(), &repos);
+ let commit_dates = commits::find_dates(gen.author.as_ref(), gen.pull, &repos);
render::gather_years(commit_dates)
}
M src/server.rs => src/server.rs +10 -10
@@ 1,5 1,5 @@
-use hyper::service::{make_service_fn, service_fn};
use hyper::header::{HeaderValue, CONTENT_TYPE};
+use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server, StatusCode};
use tokio::runtime::Runtime;
use tokio::task;
@@ 54,7 54,10 @@ pub fn run(gen: &GenerationData, ext: &ExternalResources, host: SocketAddr, cach
let server = Server::bind(&host).serve(make_service);
log::println(&format!("server started on {}", host));
if let Err(err) = server.await {
- log::println(&format!("error: hyper server encountered an error: {}", err));
+ log::println(&format!(
+ "error: hyper server encountered an error: {}",
+ err
+ ));
}
});
}
@@ 93,7 96,7 @@ fn error_response(s: &'static str, status_code: StatusCode) -> Response<Body> {
}
async fn refresh_caches() {
- let task = task::spawn_blocking(|| {
+ task::spawn_blocking(|| {
let refresh_time = {
let last_cache = LAST_CACHE.read().unwrap();
let lifetime = CACHE_LIFETIME.read().unwrap();
@@ 120,17 123,14 @@ async fn refresh_caches() {
*last_cache = Instant::now();
}
}
- log::println(
- &format!("updated cache, took {:?}", Instant::now() - start),
- );
+ log::println(&format!("updated cache, took {:?}", Instant::now() - start));
REFRESHING_CACHE.store(false, Ordering::Relaxed);
CACHE_INITIALIZED.store(true, Ordering::Relaxed);
}
});
- // If the cache hasn't been initialized yet, wait for the refresh
- // to run by `await`ing it.
- if !CACHE_INITIALIZED.load(Ordering::Relaxed) {
- let _ = task.await;
+ // Yield until the cache has been initialized
+ while !CACHE_INITIALIZED.load(Ordering::Relaxed) {
+ task::yield_now().await;
}
}