Skip to content

Commit 26d4e32

Browse files
committed
feat(core): add get_snapshot_from_strs to Repository
1 parent 2b8c4fd commit 26d4e32

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

crates/core/src/repofile/configfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct ConfigFile {
5353
/// Repository version. Currently 1 and 2 are supported
5454
pub version: u32,
5555

56-
/// The [`Id`] identifying the repsitory
56+
/// The [`Id`] identifying the repository
5757
pub id: RepositoryId,
5858

5959
/// The chunker polynomial used to chunk data

crates/core/src/repository.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
959959
/// # Returns
960960
///
961961
/// If `id` is (part of) an `Id`, return this snapshot.
962-
/// If `id` is "latest", return the latest snapshot respecting the giving filter.
962+
/// If `id` is "latest" or "latest~N", return the latest (or Nth latest) snapshot respecting the giving filter.
963963
pub fn get_snapshot_from_str(
964964
&self,
965965
id: &str,
@@ -971,6 +971,35 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
971971
Ok(snap)
972972
}
973973

974+
/// Get a single snapshot
975+
///
976+
/// # Arguments
977+
///
978+
/// * `ids` - The ids of the snapshot to get
979+
/// * each `id` can use an actual (short) id "01a2b3c4" or "latest" or "latest~N"
980+
/// * `filter` - The filter to use
981+
///
982+
/// # Errors
983+
///
984+
/// * If the string is not a valid hexadecimal string
985+
/// * If no id could be found.
986+
/// * If the id is not unique.
987+
///
988+
/// # Returns
989+
///
990+
/// If `id` is (part of) an `Id`, return this snapshot.
991+
/// If `id` is "latest" or "latest~N", return the latest (or Nth latest) snapshot respecting the giving filter.
992+
pub fn get_snapshot_from_strs<T: AsRef<str>>(
993+
&self,
994+
ids: &[T],
995+
filter: impl FnMut(&SnapshotFile) -> bool + Send + Sync,
996+
) -> RusticResult<Vec<SnapshotFile>> {
997+
let p = self.pb.progress_counter("getting snapshots...");
998+
let snaps = SnapshotFile::from_strs(self.dbe(), ids, filter, &p)?;
999+
p.finish();
1000+
Ok(snaps)
1001+
}
1002+
9741003
/// Get the given snapshots.
9751004
///
9761005
/// # Arguments

0 commit comments

Comments
 (0)