Work in progress
This commit is contained in:
112
src/lib.rs
112
src/lib.rs
@@ -1,6 +1,7 @@
|
||||
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use log::{info, trace};
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::string::String;
|
||||
use std::str;
|
||||
@@ -22,6 +23,12 @@ pub struct TargetPath
|
||||
pub destination: PathBuf,
|
||||
}
|
||||
|
||||
pub struct Job
|
||||
{
|
||||
pub id: u32,
|
||||
pub result_repository_path: PathBuf,
|
||||
}
|
||||
|
||||
impl BenchmarkRepository
|
||||
{
|
||||
fn progress_bar_style() -> ProgressStyle
|
||||
@@ -359,87 +366,88 @@ impl BenchmarkRepository
|
||||
Some(content.to_owned())
|
||||
}
|
||||
|
||||
pub fn create_result_repository(&mut self) -> PathBuf
|
||||
pub fn create_result_repository(&mut self) -> Job
|
||||
{
|
||||
let job_id = self.jobs;
|
||||
self.jobs += 1;
|
||||
|
||||
let repository_path = self.base_path.join(format!("job-{}", job_id));
|
||||
let result_repository_path = self.base_path.join(format!("job-{}", job_id));
|
||||
|
||||
if repository_path.exists()
|
||||
if result_repository_path.exists()
|
||||
{
|
||||
match std::fs::remove_dir_all(&repository_path)
|
||||
match std::fs::remove_dir_all(&result_repository_path)
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), error),
|
||||
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, result_repository_path.display(), error),
|
||||
};
|
||||
}
|
||||
|
||||
match Repository::init_bare(&repository_path)
|
||||
match Repository::init_bare(&result_repository_path)
|
||||
{
|
||||
Ok(repository) => repository,
|
||||
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), error),
|
||||
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, result_repository_path.display(), error),
|
||||
};
|
||||
|
||||
info!("Initialized result Git repository for job {} in “{}”", job_id, repository_path.display());
|
||||
info!("Initialized result Git repository for job {} in “{}”", job_id, result_repository_path.display());
|
||||
|
||||
repository_path
|
||||
Job{id: job_id, result_repository_path}
|
||||
}
|
||||
|
||||
fn tip_commit<'repository>(repository: &'repository git2::Repository, branch_name: &str) -> Result<git2::Commit<'repository>, git2::Error>
|
||||
{
|
||||
let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);
|
||||
let tip_reference = match repository.find_reference(&tip_reference_name)
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("Could not find reference “{}”: {}", tip_reference_name, error),
|
||||
};
|
||||
|
||||
tip_reference.peel_to_commit()
|
||||
}
|
||||
|
||||
pub fn join(&self)
|
||||
{
|
||||
let mut Vec<git2::Oid> job_commit_ids;
|
||||
let mut active_job_ids = HashSet::new();
|
||||
|
||||
for job_id in 0..self.jobs
|
||||
{
|
||||
active_job_ids.insert(job_id);
|
||||
}
|
||||
|
||||
loop
|
||||
{
|
||||
for job_id in 0..self.jobs
|
||||
while !active_job_ids.is_empty()
|
||||
{
|
||||
let repository_path = self.base_path.join(format!("job-{}", job_id));
|
||||
active_job_ids.retain
|
||||
(
|
||||
|job_id|
|
||||
{
|
||||
let job_repository_path = self.base_path.join(format!("job-{}", job_id));
|
||||
|
||||
let repository = match Repository::open(&repository_path)
|
||||
{
|
||||
Ok(repository) => repository,
|
||||
Err(error) => panic!("cannot access result repository for job {}: {}", job_id, error),
|
||||
};
|
||||
let job_repository = match Repository::open(&job_repository_path)
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("cannot access result repository for job {}: {}", job_id, error),
|
||||
};
|
||||
|
||||
let tip_reference_name = "refs/remotes/origin/master";
|
||||
let tip_reference = match self.repository.find_reference(&tip_reference_name)
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("error reading result repository for job {}: {}", job_id, error),
|
||||
};
|
||||
let job_commit = match Self::tip_commit(&job_repository, "master")
|
||||
{
|
||||
Ok(value) => value,
|
||||
// Job is not done yet, so skip it until it is
|
||||
Err(_) => return true,
|
||||
};
|
||||
|
||||
let commit = match tip_reference.peel_to_commit()
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("error reading result repository for job {}: {}", job_id, error),
|
||||
};
|
||||
info!("job {} finished", job_id);
|
||||
|
||||
let tree = match tip_reference.peel_to_tree()
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("Could not peel reference to tree: {}", error),
|
||||
};
|
||||
let remote_commit = match Self::tip_commit(&self.repository, "results")
|
||||
{
|
||||
Ok(value) => value,
|
||||
Err(error) => panic!("could not access tip commit of “results” branch: {}", error),
|
||||
};
|
||||
|
||||
let object_id = match tree.get_path(file_path)
|
||||
{
|
||||
Ok(tree_entry) => tree_entry.id(),
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let blob = match self.repository.find_blob(object_id)
|
||||
{
|
||||
Ok(blob) => blob,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let content = match std::str::from_utf8(blob.content())
|
||||
{
|
||||
Ok(content) => content,
|
||||
Err(error) => panic!("Could not interpret file “{}” as UTF-8: {}", file_path.display(), error),
|
||||
};
|
||||
|
||||
Some(content.to_owned())
|
||||
false
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//let origin = self.inner.repository.find_remote("origin").expect("could not find remote “origin”");
|
||||
|
Reference in New Issue
Block a user