Clean up and minor refactorings
This commit is contained in:
parent
fc7d3e5fa0
commit
3ae510e229
@ -2,13 +2,10 @@ extern crate benchmark_repository;
|
|||||||
extern crate pretty_env_logger;
|
extern crate pretty_env_logger;
|
||||||
extern crate yaml_rust;
|
extern crate yaml_rust;
|
||||||
|
|
||||||
use benchmark_repository::{BenchmarkRepository, TargetPath};
|
use benchmark_repository::BenchmarkRepository;
|
||||||
|
|
||||||
use std::io::{self, copy, Read};
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use yaml_rust::{YamlLoader, YamlEmitter};
|
use yaml_rust::YamlLoader;
|
||||||
|
|
||||||
use std::{thread, time};
|
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
@ -37,16 +34,16 @@ fn main()
|
|||||||
let file_name_base = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number);
|
let file_name_base = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number);
|
||||||
let file_name_output = format!("{}.out", file_name_base);
|
let file_name_output = format!("{}.out", file_name_base);
|
||||||
|
|
||||||
if (benchmark_repository.file_exists(Path::new(&file_name_output), "results"))
|
if benchmark_repository.file_exists(Path::new(&file_name_output), "results")
|
||||||
{
|
{
|
||||||
println!("done: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number);
|
println!("done: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let test = benchmark_repository.create_autocommit_directory(Path::new(&file_name_base), "results").unwrap();
|
let test = benchmark_repository.create_autocommit_directory(Path::new(&file_name_base), "results").unwrap();
|
||||||
//println!("{}", test.display());
|
println!("{}", test.display());
|
||||||
|
|
||||||
//println!("to do: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number);
|
println!("to do: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
src/lib.rs
55
src/lib.rs
@ -7,15 +7,13 @@ extern crate notify;
|
|||||||
extern crate tempfile;
|
extern crate tempfile;
|
||||||
extern crate walkdir;
|
extern crate walkdir;
|
||||||
|
|
||||||
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, ResetType, Repository, Signature, TreeBuilder};
|
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
|
||||||
use git2::build::{CheckoutBuilder, RepoBuilder};
|
use std::fs::{File, create_dir_all, remove_file};
|
||||||
use std::fs::{File, create_dir_all, read, remove_file};
|
|
||||||
use std::io::Cursor;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
use std::sync::mpsc::channel;
|
||||||
use std::thread::{spawn, JoinHandle};
|
use std::thread::{spawn, JoinHandle};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use notify::{raw_watcher, RecommendedWatcher, RawEvent, Op, RecursiveMode, Watcher};
|
use notify::{raw_watcher, RecommendedWatcher, RawEvent, Op, RecursiveMode, Watcher};
|
||||||
@ -33,7 +31,6 @@ pub struct BenchmarkRepositoryInner
|
|||||||
pub struct BenchmarkRepository
|
pub struct BenchmarkRepository
|
||||||
{
|
{
|
||||||
inner: Arc<Mutex<BenchmarkRepositoryInner>>,
|
inner: Arc<Mutex<BenchmarkRepositoryInner>>,
|
||||||
autocommit_channel: (Sender<RawEvent>, Receiver<RawEvent>),
|
|
||||||
autocommit_directory: Option<TempDir>,
|
autocommit_directory: Option<TempDir>,
|
||||||
autocommit_thread: Option<JoinHandle<()>>,
|
autocommit_thread: Option<JoinHandle<()>>,
|
||||||
autocommit_watcher: Option<RecommendedWatcher>,
|
autocommit_watcher: Option<RecommendedWatcher>,
|
||||||
@ -75,26 +72,15 @@ impl BenchmarkRepository
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkout_progress_callback(path: Option<&Path>, current: usize, total: usize, progress_bar: &mut ProgressBar)
|
|
||||||
{
|
|
||||||
progress_bar.set_length(total as u64);
|
|
||||||
progress_bar.set_position(current as u64);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset_origin(&self, remote_url: &str) -> &Self
|
fn reset_origin(&self, remote_url: &str) -> &Self
|
||||||
{
|
{
|
||||||
let inner = self.inner.lock().unwrap();
|
let inner = self.inner.lock().unwrap();
|
||||||
|
|
||||||
let remote = match inner.repository.find_remote("origin")
|
if let Err(error) = inner.repository.find_remote("origin")
|
||||||
|
.or_else(|_| inner.repository.remote("origin", remote_url))
|
||||||
{
|
{
|
||||||
Ok(remote) => remote,
|
panic!("Could not reset remote “origin”: {}", error);
|
||||||
Err(_) =>
|
}
|
||||||
match inner.repository.remote("origin", remote_url)
|
|
||||||
{
|
|
||||||
Ok(remote) => remote,
|
|
||||||
Err(error) => panic!("Could not reset remote “origin”: {}", error),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Reset origin to “{}”", remote_url);
|
info!("Reset origin to “{}”", remote_url);
|
||||||
|
|
||||||
@ -182,7 +168,6 @@ impl BenchmarkRepository
|
|||||||
BenchmarkRepository
|
BenchmarkRepository
|
||||||
{
|
{
|
||||||
inner: Arc::new(Mutex::new(benchmark_repository_inner)),
|
inner: Arc::new(Mutex::new(benchmark_repository_inner)),
|
||||||
autocommit_channel: channel(),
|
|
||||||
autocommit_directory: None,
|
autocommit_directory: None,
|
||||||
autocommit_thread: None,
|
autocommit_thread: None,
|
||||||
autocommit_watcher: None,
|
autocommit_watcher: None,
|
||||||
@ -360,14 +345,13 @@ impl BenchmarkRepository
|
|||||||
let object_id = match tree.get_path(file_path)
|
let object_id = match tree.get_path(file_path)
|
||||||
{
|
{
|
||||||
Ok(tree_entry) => tree_entry.id(),
|
Ok(tree_entry) => tree_entry.id(),
|
||||||
Err(error) => return false,
|
Err(_) => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let blob = match inner.repository.find_blob(object_id)
|
if let Err(_) = inner.repository.find_blob(object_id)
|
||||||
{
|
{
|
||||||
Ok(blob) => blob,
|
return false;
|
||||||
Err(error) => return false,
|
}
|
||||||
};
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -392,13 +376,13 @@ impl BenchmarkRepository
|
|||||||
let object_id = match tree.get_path(file_path)
|
let object_id = match tree.get_path(file_path)
|
||||||
{
|
{
|
||||||
Ok(tree_entry) => tree_entry.id(),
|
Ok(tree_entry) => tree_entry.id(),
|
||||||
Err(error) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let blob = match inner.repository.find_blob(object_id)
|
let blob = match inner.repository.find_blob(object_id)
|
||||||
{
|
{
|
||||||
Ok(blob) => blob,
|
Ok(blob) => blob,
|
||||||
Err(error) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let content = match std::str::from_utf8(blob.content())
|
let content = match std::str::from_utf8(blob.content())
|
||||||
@ -440,7 +424,10 @@ impl BenchmarkRepository
|
|||||||
Err(error) => panic!("Could not create filesystem watcher: {}", error),
|
Err(error) => panic!("Could not create filesystem watcher: {}", error),
|
||||||
};
|
};
|
||||||
|
|
||||||
watcher.watch(&tmp_dir, RecursiveMode::Recursive);
|
if let Err(error) = watcher.watch(&tmp_dir, RecursiveMode::Recursive)
|
||||||
|
{
|
||||||
|
panic!("Could not initiate filesystem watcher: {}", error);
|
||||||
|
}
|
||||||
|
|
||||||
self.autocommit_watcher = Some(watcher);
|
self.autocommit_watcher = Some(watcher);
|
||||||
self.autocommit_directory = Some(tmp_dir);
|
self.autocommit_directory = Some(tmp_dir);
|
||||||
@ -474,7 +461,7 @@ impl BenchmarkRepository
|
|||||||
let stripped_path = match path.strip_prefix(&autocommit_base_path)
|
let stripped_path = match path.strip_prefix(&autocommit_base_path)
|
||||||
{
|
{
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(error) => panic!("Cannot handle “remove” event for path “{}”", path.display()),
|
Err(_) => panic!("Cannot handle “remove” event for path “{}”", path.display()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut components = stripped_path.components();
|
let mut components = stripped_path.components();
|
||||||
@ -495,9 +482,9 @@ impl BenchmarkRepository
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut autocommit_locks = autocommit_locks.lock().unwrap();
|
let autocommit_locks = autocommit_locks.lock().unwrap();
|
||||||
|
|
||||||
if *autocommit_locks == 0
|
if !active && *autocommit_locks == 0
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -561,7 +548,7 @@ impl BenchmarkRepository
|
|||||||
|
|
||||||
let autocommit_thread = self.autocommit_thread;
|
let autocommit_thread = self.autocommit_thread;
|
||||||
|
|
||||||
if let Err(RecvError) = autocommit_thread.unwrap().join()
|
if let Err(_) = autocommit_thread.unwrap().join()
|
||||||
{
|
{
|
||||||
panic!("Could not join autocommit thread");
|
panic!("Could not join autocommit thread");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user