forked from mirrors/jj
index: pass base directory path by reference
This commit is contained in:
parent
b733d52557
commit
8909647d86
4 changed files with 16 additions and 16 deletions
|
@ -65,7 +65,7 @@ mod tests {
|
||||||
let temp_dir = testutils::new_temp_dir();
|
let temp_dir = testutils::new_temp_dir();
|
||||||
let mutable_segment = MutableIndexSegment::full(3, 16);
|
let mutable_segment = MutableIndexSegment::full(3, 16);
|
||||||
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
||||||
let saved_index = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let saved_index = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Box::new(mutable_segment)
|
Box::new(mutable_segment)
|
||||||
|
@ -96,7 +96,7 @@ mod tests {
|
||||||
let change_id0 = new_change_id();
|
let change_id0 = new_change_id();
|
||||||
mutable_segment.add_commit_data(id_0.clone(), change_id0.clone(), &[]);
|
mutable_segment.add_commit_data(id_0.clone(), change_id0.clone(), &[]);
|
||||||
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
||||||
let saved_index = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let saved_index = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Box::new(mutable_segment)
|
Box::new(mutable_segment)
|
||||||
|
@ -167,7 +167,7 @@ mod tests {
|
||||||
// If testing incremental indexing, write the first three commits to one file
|
// If testing incremental indexing, write the first three commits to one file
|
||||||
// now and build the remainder as another segment on top.
|
// now and build the remainder as another segment on top.
|
||||||
if incremental {
|
if incremental {
|
||||||
let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let initial_file = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ mod tests {
|
||||||
mutable_segment.add_commit_data(id_4.clone(), change_id4, &[id_1.clone()]);
|
mutable_segment.add_commit_data(id_4.clone(), change_id4, &[id_1.clone()]);
|
||||||
mutable_segment.add_commit_data(id_5.clone(), change_id5, &[id_4.clone(), id_2.clone()]);
|
mutable_segment.add_commit_data(id_5.clone(), change_id5, &[id_4.clone(), id_2.clone()]);
|
||||||
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
||||||
let saved_index = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let saved_index = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Box::new(mutable_segment)
|
Box::new(mutable_segment)
|
||||||
|
@ -293,7 +293,7 @@ mod tests {
|
||||||
&[id_1, id_2, id_3, id_4, id_5],
|
&[id_1, id_2, id_3, id_4, id_5],
|
||||||
);
|
);
|
||||||
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
let index_segment: Box<dyn IndexSegment> = if on_disk {
|
||||||
let saved_index = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let saved_index = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
Box::new(Arc::try_unwrap(saved_index).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Box::new(mutable_segment)
|
Box::new(mutable_segment)
|
||||||
|
@ -339,7 +339,7 @@ mod tests {
|
||||||
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
||||||
|
|
||||||
// Write the first three commits to one file and build the remainder on top.
|
// Write the first three commits to one file and build the remainder on top.
|
||||||
let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let initial_file = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
||||||
|
|
||||||
let id_3 = CommitId::from_hex("055444");
|
let id_3 = CommitId::from_hex("055444");
|
||||||
|
@ -411,7 +411,7 @@ mod tests {
|
||||||
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
||||||
|
|
||||||
// Write the first three commits to one file and build the remainder on top.
|
// Write the first three commits to one file and build the remainder on top.
|
||||||
let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let initial_file = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
mutable_segment = MutableIndexSegment::incremental(initial_file.clone());
|
mutable_segment = MutableIndexSegment::incremental(initial_file.clone());
|
||||||
|
|
||||||
let id_3 = CommitId::from_hex("055444");
|
let id_3 = CommitId::from_hex("055444");
|
||||||
|
@ -539,7 +539,7 @@ mod tests {
|
||||||
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
mutable_segment.add_commit_data(id_2.clone(), new_change_id(), &[]);
|
||||||
|
|
||||||
// Write the first three commits to one file and build the remainder on top.
|
// Write the first three commits to one file and build the remainder on top.
|
||||||
let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap();
|
let initial_file = mutable_segment.save_in(temp_dir.path()).unwrap();
|
||||||
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
mutable_segment = MutableIndexSegment::incremental(initial_file);
|
||||||
|
|
||||||
let id_3 = CommitId::from_hex("055444");
|
let id_3 = CommitId::from_hex("055444");
|
||||||
|
|
|
@ -20,7 +20,7 @@ use std::collections::BTreeMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Bound;
|
use std::ops::Bound;
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use blake2::Blake2b512;
|
use blake2::Blake2b512;
|
||||||
|
@ -275,7 +275,7 @@ impl MutableIndexSegment {
|
||||||
squashed
|
squashed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn save_in(self, dir: PathBuf) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
pub(super) fn save_in(self, dir: &Path) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
||||||
if self.segment_num_commits() == 0 && self.parent_file.is_some() {
|
if self.segment_num_commits() == 0 && self.parent_file.is_some() {
|
||||||
return Ok(self.parent_file.unwrap());
|
return Ok(self.parent_file.unwrap());
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ impl MutableIndexSegment {
|
||||||
let index_file_id_hex = hex::encode(hasher.finalize());
|
let index_file_id_hex = hex::encode(hasher.finalize());
|
||||||
let index_file_path = dir.join(&index_file_id_hex);
|
let index_file_path = dir.join(&index_file_id_hex);
|
||||||
|
|
||||||
let mut temp_file = NamedTempFile::new_in(&dir)?;
|
let mut temp_file = NamedTempFile::new_in(dir)?;
|
||||||
let file = temp_file.as_file_mut();
|
let file = temp_file.as_file_mut();
|
||||||
file.write_all(&buf)?;
|
file.write_all(&buf)?;
|
||||||
persist_content_addressed_temp_file(temp_file, index_file_path)?;
|
persist_content_addressed_temp_file(temp_file, index_file_path)?;
|
||||||
|
@ -412,7 +412,7 @@ impl DefaultMutableIndex {
|
||||||
self.0.add_commit_data(commit_id, change_id, parent_ids);
|
self.0.add_commit_data(commit_id, change_id, parent_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn save_in(self, dir: PathBuf) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
pub(super) fn save_in(self, dir: &Path) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
||||||
self.0.save_in(dir)
|
self.0.save_in(dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::cmp::Ordering;
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
|
@ -148,7 +148,7 @@ impl Debug for ReadonlyIndexSegment {
|
||||||
impl ReadonlyIndexSegment {
|
impl ReadonlyIndexSegment {
|
||||||
pub(super) fn load_from(
|
pub(super) fn load_from(
|
||||||
file: &mut dyn Read,
|
file: &mut dyn Read,
|
||||||
dir: PathBuf,
|
dir: &Path,
|
||||||
name: String,
|
name: String,
|
||||||
commit_id_length: usize,
|
commit_id_length: usize,
|
||||||
change_id_length: usize,
|
change_id_length: usize,
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl DefaultIndexStore {
|
||||||
let mut index_file = File::open(index_file_path).unwrap();
|
let mut index_file = File::open(index_file_path).unwrap();
|
||||||
ReadonlyIndexSegment::load_from(
|
ReadonlyIndexSegment::load_from(
|
||||||
&mut index_file,
|
&mut index_file,
|
||||||
self.dir.to_owned(),
|
&self.dir,
|
||||||
index_file_id_hex,
|
index_file_id_hex,
|
||||||
commit_id_length,
|
commit_id_length,
|
||||||
change_id_length,
|
change_id_length,
|
||||||
|
@ -197,7 +197,7 @@ impl DefaultIndexStore {
|
||||||
op_id: &OperationId,
|
op_id: &OperationId,
|
||||||
) -> Result<Arc<ReadonlyIndexSegment>, DefaultIndexStoreError> {
|
) -> Result<Arc<ReadonlyIndexSegment>, DefaultIndexStoreError> {
|
||||||
let index_segment = mutable_index
|
let index_segment = mutable_index
|
||||||
.save_in(self.dir.clone())
|
.save_in(&self.dir)
|
||||||
.map_err(DefaultIndexStoreError::SaveIndex)?;
|
.map_err(DefaultIndexStoreError::SaveIndex)?;
|
||||||
self.associate_file_with_operation(&index_segment, op_id)
|
self.associate_file_with_operation(&index_segment, op_id)
|
||||||
.map_err(|source| DefaultIndexStoreError::AssociateIndex {
|
.map_err(|source| DefaultIndexStoreError::AssociateIndex {
|
||||||
|
|
Loading…
Reference in a new issue