forked from mirrors/jj
index: let caller of segment-level save-in() squash segments explicitly
There are many unit tests that call mutable_segment.save_in(), but I don't think these callers expect that the segment file could be squashed depending on the size. Let's make it caller's responsibility. maybe_squash_with_ancestors() should be cheap if segment_num_commits() == 0, so it's okay to call it before checking the emptiness.
This commit is contained in:
parent
1d80bbb70a
commit
320d15412b
2 changed files with 8 additions and 9 deletions
|
@ -273,11 +273,10 @@ impl MutableIndexSegment {
|
|||
return Ok(self.parent_file.unwrap());
|
||||
}
|
||||
|
||||
let squashed = self.maybe_squash_with_ancestors();
|
||||
let mut buf = Vec::new();
|
||||
squashed.serialize_parent_filename(&mut buf);
|
||||
self.serialize_parent_filename(&mut buf);
|
||||
let local_entries_offset = buf.len();
|
||||
squashed.serialize_local_entries(&mut buf);
|
||||
self.serialize_local_entries(&mut buf);
|
||||
let mut hasher = Blake2b512::new();
|
||||
hasher.update(&buf);
|
||||
let index_file_id_hex = hex::encode(hasher.finalize());
|
||||
|
@ -291,9 +290,9 @@ impl MutableIndexSegment {
|
|||
Ok(ReadonlyIndexSegment::load_with_parent_file(
|
||||
&mut &buf[local_entries_offset..],
|
||||
index_file_id_hex,
|
||||
squashed.parent_file,
|
||||
squashed.commit_id_length,
|
||||
squashed.change_id_length,
|
||||
self.parent_file,
|
||||
self.commit_id_length,
|
||||
self.change_id_length,
|
||||
)
|
||||
.expect("in-memory index data should be valid and readable"))
|
||||
}
|
||||
|
@ -405,8 +404,8 @@ impl DefaultMutableIndex {
|
|||
self.0.add_commit_data(commit_id, change_id, parent_ids);
|
||||
}
|
||||
|
||||
pub(super) fn save_in(self, dir: &Path) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
||||
self.0.save_in(dir)
|
||||
pub(super) fn squash_and_save_in(self, dir: &Path) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
||||
self.0.maybe_squash_with_ancestors().save_in(dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ impl DefaultIndexStore {
|
|||
op_id: &OperationId,
|
||||
) -> Result<Arc<ReadonlyIndexSegment>, DefaultIndexStoreError> {
|
||||
let index_segment = mutable_index
|
||||
.save_in(&self.dir)
|
||||
.squash_and_save_in(&self.dir)
|
||||
.map_err(DefaultIndexStoreError::SaveIndex)?;
|
||||
self.associate_file_with_operation(&index_segment, op_id)
|
||||
.map_err(|source| DefaultIndexStoreError::AssociateIndex {
|
||||
|
|
Loading…
Reference in a new issue