diff --git a/lib/src/index.rs b/lib/src/index.rs index d16d95bca..2497ae5b0 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -28,8 +28,6 @@ use tempfile::NamedTempFile; use crate::commit::Commit; -use crate::op_store::OperationId; - use crate::store::{ChangeId, CommitId}; use std::fmt::{Debug, Formatter}; @@ -1344,19 +1342,14 @@ impl ReadonlyIndex { })) } - /// Records a link from the given operation to the this index version. - pub fn associate_with_operation(&self, op_id: &OperationId) -> io::Result<()> { - let mut temp_file = NamedTempFile::new_in(&self.dir)?; - let file = temp_file.as_file_mut(); - file.write_all(&self.name.as_bytes()).unwrap(); - temp_file.persist(&self.dir.join("operations").join(op_id.hex()))?; - Ok(()) - } - pub fn num_commits(&self) -> u32 { CompositeIndex(self).num_commits() } + pub fn name(&self) -> &str { + &self.name + } + pub fn stats(&self) -> IndexStats { CompositeIndex(self).stats() } diff --git a/lib/src/index_store.rs b/lib/src/index_store.rs index 7a506d185..c31ee8853 100644 --- a/lib/src/index_store.rs +++ b/lib/src/index_store.rs @@ -23,9 +23,10 @@ use crate::store_wrapper::StoreWrapper; use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io; -use std::io::Read; +use std::io::{Read, Write}; use std::path::PathBuf; use std::sync::Arc; +use tempfile::NamedTempFile; pub struct IndexStore { dir: PathBuf, @@ -132,10 +133,23 @@ impl IndexStore { let index_file = data.save()?; - index_file.associate_with_operation(operation.id())?; + self.associate_file_with_operation(&index_file, operation.id())?; Ok(index_file) } + + /// Records a link from the given operation to the this index version. + pub fn associate_file_with_operation( + &self, + index: &ReadonlyIndex, + op_id: &OperationId, + ) -> io::Result<()> { + let mut temp_file = NamedTempFile::new_in(&self.dir)?; + let file = temp_file.as_file_mut(); + file.write_all(&index.name().as_bytes()).unwrap(); + temp_file.persist(&self.dir.join("operations").join(op_id.hex()))?; + Ok(()) + } } // Returns the ancestors of heads with parents and predecessors come before the diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 8414cd541..d2789dfec 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -298,6 +298,10 @@ impl ReadonlyRepo { &self.store } + pub fn index_store(&self) -> &IndexStore { + &self.index_store + } + pub fn settings(&self) -> &RepoSettings { &self.settings } diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 581a17f3f..38dcb4ecb 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -202,10 +202,13 @@ impl<'r> Transaction<'r> { pub fn commit(mut self) -> Operation { let mut_repo = Arc::try_unwrap(self.repo.take().unwrap()).ok().unwrap(); + let index_store = mut_repo.base_repo().index_store(); let (mut_index, mut_view) = mut_repo.consume(); let index = mut_index.save().unwrap(); let operation = mut_view.save(self.description.clone(), self.start_time.clone()); - index.associate_with_operation(operation.id()).unwrap(); + index_store + .associate_file_with_operation(&index, operation.id()) + .unwrap(); self.closed = true; operation }