Start implementing new synchronization mechanism

This one is based on separate Git repositories for results.
This commit is contained in:
2019-03-01 15:57:35 +01:00
parent 8a05af9b25
commit 3c2d03dc38
3 changed files with 34 additions and 42 deletions

View File

@@ -9,6 +9,7 @@ use walkdir::WalkDir;
pub struct BenchmarkRepositoryInner
{
base_path: PathBuf,
repository: Repository,
ssh_user: String,
user_name: String,
@@ -114,20 +115,22 @@ impl BenchmarkRepository
fn init(base_path: &Path) -> Repository
{
let repository = match Repository::init_bare(base_path)
let repository_path = base_path.join("upstream");
let repository = match Repository::init_bare(&repository_path)
{
Ok(repository) => repository,
Err(error) => panic!("failed to initialize Git repository in “{}”: {}", base_path.display(), error),
Err(error) => panic!("failed to initialize Git repository in “{}”: {}", repository_path.display(), error),
};
info!("Initialized Git repository in “{}”", base_path.display());
info!("Initialized Git repository in “{}”", repository_path.display());
repository
}
pub fn new(remote_url: &str, base_path: &Path, ssh_user: &str, user_name: &str, user_email: &str) -> BenchmarkRepository
pub fn new(remote_url: &str, base_path: PathBuf, ssh_user: &str, user_name: &str, user_email: &str) -> BenchmarkRepository
{
let repository = match Repository::open(base_path)
let repository = match Repository::open(&base_path)
{
Ok(repository) =>
{
@@ -135,12 +138,13 @@ impl BenchmarkRepository
repository
},
Err(_) => BenchmarkRepository::init(base_path),
Err(_) => BenchmarkRepository::init(&base_path),
};
let benchmark_repository_inner =
BenchmarkRepositoryInner
{
base_path: base_path,
repository: repository,
ssh_user: ssh_user.to_string(),
user_name: user_name.to_string(),
@@ -373,42 +377,30 @@ impl BenchmarkRepository
Some(content.to_owned())
}
pub fn create_branch_for_job(&self, job_id: u32) -> String
pub fn create_result_repository_for_job(&self, job_id: u32) -> PathBuf
{
let inner = self.inner.clone();
let empty_tree_hash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
let empty_tree_object_id = Oid::from_str(&empty_tree_hash).unwrap();
let empty_tree = match inner.repository.find_tree(empty_tree_object_id)
let repository_path = inner.base_path.join(format!("job-{}", job_id));
if repository_path.exists()
{
Ok(value) => value,
Err(error) => panic!("Could not find empty tree object: {}", error),
match std::fs::remove_dir_all(&repository_path)
{
Ok(_) => (),
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), error),
};
}
match Repository::init_bare(&repository_path)
{
Ok(repository) => repository,
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), error),
};
let signature = Signature::now(&inner.user_name, &inner.user_email).expect("Could not create signature");
let message = format!("Initial commit for job {}", job_id);
info!("Initialized result Git repository for job {} in “{}”", job_id, repository_path.display());
let commit_id = match inner.repository.commit(None, &signature, &signature, &message, &empty_tree, &[])
{
Ok(value) => value,
Err(error) => panic!("Could not write commit: {}", error),
};
let commit = match inner.repository.find_commit(commit_id)
{
Ok(value) => value,
Err(error) => panic!("Could not find newly written commit: {}", error),
};
let branch_name = format!("__job_{}", job_id);
match inner.repository.branch(&branch_name, &commit, true)
{
Ok(_) => println!("Created new branch “{}", branch_name),
Err(error) => panic!("Could not create job branch “{}”: {}", branch_name, error),
};
branch_name
repository_path
}
pub fn join(&self)