mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-31 00:12:06 +00:00
index: move ReadonlyFile::associate_with_operation() to IndexStore
After this patch, the `index` module no longer knows about the ".jj/index/operations/" directory; that knowledge is now only in `IndexStore`.
This commit is contained in:
parent
c4fe7aab10
commit
502ba895f5
4 changed files with 28 additions and 14 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -298,6 +298,10 @@ impl ReadonlyRepo {
|
|||
&self.store
|
||||
}
|
||||
|
||||
pub fn index_store(&self) -> &IndexStore {
|
||||
&self.index_store
|
||||
}
|
||||
|
||||
pub fn settings(&self) -> &RepoSettings {
|
||||
&self.settings
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue