Clean up and minor refactorings

This commit is contained in:
Patrick Lühne 2018-10-04 17:33:03 +02:00
parent fc7d3e5fa0
commit 3ae510e229
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 26 additions and 42 deletions

View File

@ -2,13 +2,10 @@ extern crate benchmark_repository;
extern crate pretty_env_logger;
extern crate yaml_rust;
use benchmark_repository::{BenchmarkRepository, TargetPath};
use benchmark_repository::BenchmarkRepository;
use std::io::{self, copy, Read};
use std::path::Path;
use yaml_rust::{YamlLoader, YamlEmitter};
use std::{thread, time};
use yaml_rust::YamlLoader;
fn main()
{
@ -37,16 +34,16 @@ fn main()
let file_name_base = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number);
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);
continue;
}
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);
}
}
}

View File

@ -7,15 +7,13 @@ extern crate notify;
extern crate tempfile;
extern crate walkdir;
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, ResetType, Repository, Signature, TreeBuilder};
use git2::build::{CheckoutBuilder, RepoBuilder};
use std::fs::{File, create_dir_all, read, remove_file};
use std::io::Cursor;
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use std::fs::{File, create_dir_all, remove_file};
use std::path::{Path, PathBuf};
use std::string::String;
use std::str;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::mpsc::channel;
use std::thread::{spawn, JoinHandle};
use indicatif::{ProgressBar, ProgressStyle};
use notify::{raw_watcher, RecommendedWatcher, RawEvent, Op, RecursiveMode, Watcher};
@ -33,7 +31,6 @@ pub struct BenchmarkRepositoryInner
pub struct BenchmarkRepository
{
inner: Arc<Mutex<BenchmarkRepositoryInner>>,
autocommit_channel: (Sender<RawEvent>, Receiver<RawEvent>),
autocommit_directory: Option<TempDir>,
autocommit_thread: Option<JoinHandle<()>>,
autocommit_watcher: Option<RecommendedWatcher>,
@ -75,26 +72,15 @@ impl BenchmarkRepository
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
{
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,
Err(_) =>
match inner.repository.remote("origin", remote_url)
{
Ok(remote) => remote,
Err(error) => panic!("Could not reset remote “origin”: {}", error),
},
};
panic!("Could not reset remote “origin”: {}", error);
}
info!("Reset origin to “{}”", remote_url);
@ -182,7 +168,6 @@ impl BenchmarkRepository
BenchmarkRepository
{
inner: Arc::new(Mutex::new(benchmark_repository_inner)),
autocommit_channel: channel(),
autocommit_directory: None,
autocommit_thread: None,
autocommit_watcher: None,
@ -360,14 +345,13 @@ impl BenchmarkRepository
let object_id = match tree.get_path(file_path)
{
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,
Err(error) => return false,
};
return false;
}
true
}
@ -392,13 +376,13 @@ impl BenchmarkRepository
let object_id = match tree.get_path(file_path)
{
Ok(tree_entry) => tree_entry.id(),
Err(error) => return None,
Err(_) => return None,
};
let blob = match inner.repository.find_blob(object_id)
{
Ok(blob) => blob,
Err(error) => return None,
Err(_) => return None,
};
let content = match std::str::from_utf8(blob.content())
@ -440,7 +424,10 @@ impl BenchmarkRepository
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_directory = Some(tmp_dir);
@ -474,7 +461,7 @@ impl BenchmarkRepository
let stripped_path = match path.strip_prefix(&autocommit_base_path)
{
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();
@ -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;
}
@ -561,7 +548,7 @@ impl BenchmarkRepository
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");
}