From 3d3580d845b641ed9c72b123fb8e22a98bc01707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 2 Mar 2019 03:48:49 +0100 Subject: [PATCH] Clean-up --- src/lib.rs | 167 ----------------------------------------------------- 1 file changed, 167 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 344af2b..0356caa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,6 @@ use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::string::String; use std::str; -//use walkdir::WalkDir; pub struct Job { @@ -194,172 +193,6 @@ impl BenchmarkRepository benchmark_repository } - /*fn create_file_index_entry(&self, object_id: Oid, result_file_path: &Path) -> IndexEntry - { - IndexEntry - { - ctime: IndexTime::new(0, 0), - mtime: IndexTime::new(0, 0), - dev: 0, - ino: 0, - mode: 0o100644, - uid: 0, - gid: 0, - file_size: 0, - id: object_id, - flags: 0, - flags_extended: 0, - path: result_file_path.to_string_lossy().as_bytes().to_owned(), - } - }*/ - - /*fn create_directory_index_entry(&self, object_id: Oid, result_file_path: &Path) -> IndexEntry - { - IndexEntry - { - ctime: IndexTime::new(0, 0), - mtime: IndexTime::new(0, 0), - dev: 0, - ino: 0, - mode: 0o100755, - uid: 0, - gid: 0, - file_size: 0, - id: object_id, - flags: 0, - flags_extended: 0, - path: result_file_path.to_string_lossy().as_bytes().to_owned(), - } - }*/ - - /*fn read_file_as_index_entry(&self, file_path: &Path, result_file_path: &Path) -> IndexEntry - { - // create a new blob with the file contents - let object_id = match self.repository.blob_path(file_path) - { - Ok(object_id) => object_id, - Err(error) => panic!("Could not write blob for “{}”: {}", file_path.display(), error), - }; - - info!("Created object “{}” from “{}”", object_id, file_path.display()); - - self.create_file_index_entry(object_id, result_file_path) - } - - pub fn commit_directory(&self, directory_path: &TargetPath, branch_name: &str) - { - let mut file_paths = vec![]; - - for entry in WalkDir::new(&directory_path.source) - { - let entry = entry.unwrap(); - - if entry.path().file_name().unwrap() == ".lock" || entry.file_type().is_dir() - { - continue; - } - - let relative_path = entry.path().strip_prefix(&directory_path.source).unwrap(); - - trace!("Adding “{}” (from “{}”) to autocommit list", relative_path.display(), entry.path().display()); - - file_paths.push(TargetPath{source: entry.path().to_owned(), destination: directory_path.destination.join(&relative_path)}); - } - - self.commit_files(&file_paths, branch_name); - } - - pub fn commit_files(&self, file_paths: &[TargetPath], branch_name: &str) - { - let tip_reference_name = format!("refs/remotes/origin/{}", branch_name); - let tip_reference = match self.repository.find_reference(&tip_reference_name) - { - Ok(value) => value, - Err(error) => panic!("Could not find reference “{}”: {}", tip_reference_name, error), - }; - - let parent_tree = match tip_reference.peel_to_tree() - { - Ok(value) => value, - Err(error) => panic!("Could not peel reference to tree: {}", error), - }; - - let mut index = match Index::new() - { - Ok(value) => value, - Err(error) => panic!("Could not create index: {}", error), - }; - - match index.read_tree(&parent_tree) - { - Ok(value) => value, - Err(error) => panic!("Could not read parent tree into index: {}", error), - }; - - for target_path in file_paths - { - let index_entry = self.read_file_as_index_entry(&target_path.source, &target_path.destination); - - if let Err(error) = index.add(&index_entry) - { - panic!("Could not add index entry for “{}”: {}", target_path.destination.display(), error); - } - } - - let tree_object_id = match index.write_tree_to(&self.repository) - { - Ok(value) => value, - Err(error) => panic!("Could not write index to tree: {}", error), - }; - - let tree = match self.repository.find_tree(tree_object_id) - { - Ok(value) => value, - Err(error) => panic!("Could obtain tree: {}", error), - }; - - info!("Created tree object “{}”", tree_object_id); - - let signature = Signature::now(&self.user_name, &self.user_email).expect("Could not create signature"); - let message = format!("Add files"); - - let parent = match tip_reference.peel_to_commit() - { - Ok(value) => value, - Err(error) => panic!("Could not peel reference: {}", error), - }; - - let commit_id = match self.repository.commit(Some(&tip_reference_name), &signature, &signature, &message, &tree, &[&parent]) - { - Ok(value) => value, - Err(error) => panic!("Could not write commit: {}", error), - }; - - let push_refspec = format!("refs/remotes/origin/{}:refs/heads/{}", branch_name, branch_name); - - trace!("Created commit “{}”, using refspec “{}”", commit_id, push_refspec); - - let mut remote_callbacks = RemoteCallbacks::new(); - remote_callbacks.credentials( - |_, _, _| - { - match Cred::ssh_key_from_agent(&self.ssh_user) - { - Ok(value) => Ok(value), - Err(error) => panic!("could not retrieve key pair for SSH authentication as user “{}”: {}", self.ssh_user, error), - } - }); - - remote_callbacks.push_update_reference( - |reference, status| BenchmarkRepository::push_update_reference_callback(reference, status)); - - let mut push_options = PushOptions::new(); - push_options.remote_callbacks(remote_callbacks); - - let mut remote = self.repository.find_remote("origin").expect(""); - remote.push(&[&push_refspec], Some(&mut push_options)).expect("couldn’t push"); - }*/ - pub fn file_exists(&self, file_path: &Path, branch_name: &str) -> bool { let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);