New implementation using two indexes

This commit is contained in:
Patrick Lühne 2019-03-02 03:35:15 +01:00
parent dc842289d2
commit 0b29ffc410
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 30 additions and 12 deletions

View File

@ -179,7 +179,7 @@ impl BenchmarkRepository
} }
}*/ }*/
fn create_directory_index_entry(&self, object_id: Oid, result_file_path: &Path) -> IndexEntry /*fn create_directory_index_entry(&self, object_id: Oid, result_file_path: &Path) -> IndexEntry
{ {
IndexEntry IndexEntry
{ {
@ -196,7 +196,7 @@ impl BenchmarkRepository
flags_extended: 0, flags_extended: 0,
path: result_file_path.to_string_lossy().as_bytes().to_owned(), 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 /*fn read_file_as_index_entry(&self, file_path: &Path, result_file_path: &Path) -> IndexEntry
{ {
@ -463,13 +463,13 @@ impl BenchmarkRepository
info!("job {} finished ({})", job_id, job.key); info!("job {} finished ({})", job_id, job.key);
let remote_commit = match self.tip_commit("origin", "results") let upstream_commit = match self.tip_commit("origin", "results")
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not access tip commit of “results” branch: {}", error), Err(error) => panic!("could not access tip commit of “results” branch: {}", error),
}; };
let remote_tree = match remote_commit.tree() let upstream_tree = match upstream_commit.tree()
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not access tip commit tree of “results” branch: {}", error), Err(error) => panic!("could not access tip commit tree of “results” branch: {}", error),
@ -481,26 +481,44 @@ impl BenchmarkRepository
Err(error) => panic!("cannot read results of job {}: {}", job_id, error), Err(error) => panic!("cannot read results of job {}: {}", job_id, error),
}; };
let mut index = match Index::new() let mut upstream_index = match Index::new()
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not create index: {}", error), Err(error) => panic!("could not create index: {}", error),
}; };
match index.read_tree(&remote_tree) match upstream_index.read_tree(&upstream_tree)
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not read tree into index: {}", error), Err(error) => panic!("could not read tree into index: {}", error),
}; };
let result_path = Path::new(&job.key); let mut job_index = match Index::new()
match index.add(&self.create_directory_index_entry(job_tree.id(), &result_path))
{ {
Ok(_) => (), Ok(value) => value,
Err(error) => panic!("could not add results to index: {}", error), Err(error) => panic!("could not create index: {}", error),
}; };
let new_tree_object_id = match index.write_tree_to(&self.repository) match job_index.read_tree(&job_tree)
{
Ok(value) => value,
Err(error) => panic!("could not read tree into index: {}", error),
};
for mut job_index_entry in job_index.iter()
{
let result_path = Path::new(&job.key);
job_index_entry.path = format!("{}/{}", result_path.display(), String::from_utf8_lossy(&job_index_entry.path)).as_bytes().to_owned();
match upstream_index.add(&job_index_entry)
{
Ok(_) => (),
Err(error) => panic!("could not add results to index: {}", error),
};
}
let new_tree_object_id = match upstream_index.write_tree_to(&self.repository)
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not write index to tree: {}", error), Err(error) => panic!("could not write index to tree: {}", error),
@ -519,7 +537,7 @@ impl BenchmarkRepository
let message = job_commit.message().unwrap_or(""); let message = job_commit.message().unwrap_or("");
let tip_reference_name = "refs/remotes/origin/results"; let tip_reference_name = "refs/remotes/origin/results";
let commit_id = match self.repository.commit(Some(&tip_reference_name), &author, &committer, &message, &new_tree, &[&remote_commit]) let commit_id = match self.repository.commit(Some(&tip_reference_name), &author, &committer, &message, &new_tree, &[&upstream_commit])
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("could not write commit: {}", error), Err(error) => panic!("could not write commit: {}", error),