Skip to content

Commit

Permalink
index: pass base directory path by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Dec 17, 2023
1 parent 2e85430 commit 5ded542
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions lib/src/default_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let mutable_segment = MutableIndexSegment::full(3, 16);
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())
} else {
Box::new(mutable_segment)
Expand Down Expand Up @@ -96,7 +96,7 @@ mod tests {
let change_id0 = new_change_id();
mutable_segment.add_commit_data(id_0.clone(), change_id0.clone(), &[]);
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())
} else {
Box::new(mutable_segment)
Expand Down Expand Up @@ -167,7 +167,7 @@ mod tests {
// If testing incremental indexing, write the first three commits to one file
// now and build the remainder as another segment on top.
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);
}

Expand All @@ -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_5.clone(), change_id5, &[id_4.clone(), id_2.clone()]);
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())
} else {
Box::new(mutable_segment)
Expand Down Expand Up @@ -293,7 +293,7 @@ mod tests {
&[id_1, id_2, id_3, id_4, id_5],
);
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())
} else {
Box::new(mutable_segment)
Expand Down Expand Up @@ -339,7 +339,7 @@ mod tests {
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.
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);

let id_3 = CommitId::from_hex("055444");
Expand Down Expand Up @@ -411,7 +411,7 @@ mod tests {
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.
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());

let id_3 = CommitId::from_hex("055444");
Expand Down Expand Up @@ -539,7 +539,7 @@ mod tests {
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.
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);

let id_3 = CommitId::from_hex("055444");
Expand Down
8 changes: 4 additions & 4 deletions lib/src/default_index/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::collections::BTreeMap;
use std::io;
use std::io::Write;
use std::ops::Bound;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;

use blake2::Blake2b512;
Expand Down Expand Up @@ -275,7 +275,7 @@ impl MutableIndexSegment {
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() {
return Ok(self.parent_file.unwrap());
}
Expand All @@ -289,7 +289,7 @@ impl MutableIndexSegment {
let index_file_id_hex = hex::encode(hasher.finalize());
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();
file.write_all(&buf)?;
persist_content_addressed_temp_file(temp_file, index_file_path)?;
Expand Down Expand Up @@ -412,7 +412,7 @@ impl DefaultMutableIndex {
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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/default_index/readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::cmp::Ordering;
use std::fmt::{Debug, Formatter};
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;

use byteorder::{LittleEndian, ReadBytesExt};
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Debug for ReadonlyIndexSegment {
impl ReadonlyIndexSegment {
pub(super) fn load_from(
file: &mut dyn Read,
dir: PathBuf,
dir: &Path,
name: String,
commit_id_length: usize,
change_id_length: usize,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/default_index/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl DefaultIndexStore {
let mut index_file = File::open(index_file_path).unwrap();
ReadonlyIndexSegment::load_from(
&mut index_file,
self.dir.to_owned(),
&self.dir,
index_file_id_hex,
commit_id_length,
change_id_length,
Expand Down Expand Up @@ -197,7 +197,7 @@ impl DefaultIndexStore {
op_id: &OperationId,
) -> Result<Arc<ReadonlyIndexSegment>, DefaultIndexStoreError> {
let index_segment = mutable_index
.save_in(self.dir.clone())
.save_in(&self.dir)
.map_err(DefaultIndexStoreError::SaveIndex)?;
self.associate_file_with_operation(&index_segment, op_id)
.map_err(|source| DefaultIndexStoreError::AssociateIndex {
Expand Down

0 comments on commit 5ded542

Please sign in to comment.