diff --git a/benchmark-new/benchmark_repository/examples/test.rs b/benchmark-new/benchmark_repository/examples/test.rs index 22621e5c2..703db2432 100644 --- a/benchmark-new/benchmark_repository/examples/test.rs +++ b/benchmark-new/benchmark_repository/examples/test.rs @@ -1,7 +1,7 @@ extern crate benchmark_repository; extern crate pretty_env_logger; -use benchmark_repository::BenchmarkRepository; +use benchmark_repository::{BenchmarkRepository, TargetPath}; use std::path::Path; @@ -10,5 +10,12 @@ fn main() pretty_env_logger::init(); let benchmark_repository = BenchmarkRepository::new("git@git.luehne.de:patrick/tplp-planning-benchmark.git", Path::new("storage"), "git", "Potassco Bot", "bot@potassco.org"); - benchmark_repository.commit_file(Path::new("/tmp/test"), Path::new("test-new/fourth"), "test-results"); + + let files = vec! + [ + TargetPath{source: &Path::new("/tmp/test"), destination: &Path::new("foobar/test")}, + TargetPath{source: &Path::new("/tmp/test2"), destination: &Path::new("foobar/test-2")}, + ]; + + benchmark_repository.commit_files(&files[..], "test-results"); } diff --git a/benchmark-new/benchmark_repository/src/lib.rs b/benchmark-new/benchmark_repository/src/lib.rs index e625c9f63..0a873d923 100644 --- a/benchmark-new/benchmark_repository/src/lib.rs +++ b/benchmark-new/benchmark_repository/src/lib.rs @@ -20,6 +20,12 @@ pub struct BenchmarkRepository user_email: String, } +pub struct TargetPath<'a> +{ + pub source: &'a Path, + pub destination: &'a Path, +} + impl BenchmarkRepository { fn progress_bar_style() -> ProgressStyle @@ -230,7 +236,7 @@ impl BenchmarkRepository } } - pub fn commit_file(&self, file_path: &Path, result_file_path: &Path, branch_name: &str) + 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) @@ -257,11 +263,14 @@ impl BenchmarkRepository Err(error) => panic!("Could not read parent tree into index: {}", error), }; - let index_entry = self.read_file_as_index_entry(file_path, result_file_path); - - if let Err(error) = index.add(&index_entry) + for target_path in file_paths { - panic!("Could not add index entry: {}", error); + 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) @@ -279,7 +288,7 @@ impl BenchmarkRepository 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 file “{}”", result_file_path.display()); + let message = format!("Add files"); let parent = match tip_reference.peel_to_commit() {