Test running sbatch command

This commit is contained in:
2018-10-12 17:37:08 +02:00
parent 3c79c4c113
commit c953e724cc
2 changed files with 97 additions and 9 deletions

View File

@@ -6,11 +6,11 @@ extern crate indicatif;
extern crate tempfile;
extern crate walkdir;
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use std::path::{Path, PathBuf};
use std::string::String;
use std::str;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use indicatif::{ProgressBar, ProgressStyle};
use walkdir::WalkDir;
@@ -24,7 +24,7 @@ pub struct BenchmarkRepositoryInner
pub struct BenchmarkRepository
{
inner: Arc<Mutex<BenchmarkRepositoryInner>>
inner: Arc<BenchmarkRepositoryInner>
}
pub struct TargetPath
@@ -64,7 +64,7 @@ impl BenchmarkRepository
fn reset_origin(&self, remote_url: &str) -> &Self
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
if let Err(error) = inner.repository.find_remote("origin")
.or_else(|_| inner.repository.remote("origin", remote_url))
@@ -79,7 +79,7 @@ impl BenchmarkRepository
fn fetch_branch(&self, branch_name: &str) -> &Self
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let mut progress_bar = ProgressBar::new(0);
progress_bar.set_style(BenchmarkRepository::progress_bar_style());
@@ -157,7 +157,7 @@ impl BenchmarkRepository
let benchmark_repository =
BenchmarkRepository
{
inner: Arc::new(Mutex::new(benchmark_repository_inner)),
inner: Arc::new(benchmark_repository_inner),
};
benchmark_repository
@@ -313,7 +313,7 @@ impl BenchmarkRepository
pub fn file_exists(&self, file_path: &Path, branch_name: &str) -> bool
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);
let tip_reference = match inner.repository.find_reference(&tip_reference_name)
@@ -344,7 +344,7 @@ impl BenchmarkRepository
pub fn read_file(&self, file_path: &Path, branch_name: &str) -> Option<String>
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);
let tip_reference = match inner.repository.find_reference(&tip_reference_name)
@@ -379,6 +379,65 @@ impl BenchmarkRepository
Some(content.to_owned())
}
pub fn create_branch_for_job(&self, job_id: u32) -> String
{
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)
{
Ok(value) => value,
Err(error) => panic!("Could not find empty tree object: {}", 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);
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
}
pub fn join(&self)
{
loop
{
//let origin = self.inner.repository.find_remote("origin").expect("could not find remote “origin”");
for reference in self.inner.repository.references().unwrap().names()
{
println!("{}", reference.unwrap());
}
println!("================");
use std::{thread, time};
let time = time::Duration::from_secs(2);
thread::sleep(time);
}
}
}
#[cfg(test)]