Skip to content

Commit 9615f80

Browse files
committed
feat: broad snapshot id for the cat command
1 parent 2b8c4fd commit 9615f80

File tree

1 file changed

+13
-2
lines changed
  • crates/core/src/commands

1 file changed

+13
-2
lines changed

crates/core/src/commands/cat.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33
use bytes::Bytes;
44

55
use crate::{
6+
Progress,
67
backend::{FileType, FindInBackend, decrypt::DecryptReadBackend},
78
blob::{BlobId, BlobType, tree::Tree},
89
error::{ErrorKind, RusticError, RusticResult},
@@ -24,6 +25,7 @@ use crate::{
2425
/// * `repo` - The repository to read from.
2526
/// * `tpe` - The type of the file.
2627
/// * `id` - The id of the file.
28+
/// * the `id` can **also** be in the `latest` or `latest~N` (with N >= 0) for `tpe=FileType::SnapshotFile`
2729
///
2830
/// # Errors
2931
///
@@ -38,8 +40,17 @@ pub(crate) fn cat_file<P, S: Open>(
3840
repo: &Repository<P, S>,
3941
tpe: FileType,
4042
id: &str,
41-
) -> RusticResult<Bytes> {
42-
let id = repo.dbe().find_id(tpe, id)?;
43+
) -> RusticResult<Bytes>
44+
where
45+
P: Progress,
46+
{
47+
// For SnapshotFile, using `SnapshotFile::from_str` allows `latest~N` syntax
48+
let id = if let FileType::Snapshot = tpe {
49+
let snap_file = SnapshotFile::from_str(repo.dbe(), id, |_| true, &repo.pb)?;
50+
snap_file.id.into_inner()
51+
} else {
52+
repo.dbe().find_id(tpe, id)?
53+
};
4354
let data = repo.dbe().read_encrypted_full(tpe, &id)?;
4455
Ok(data)
4556
}

0 commit comments

Comments
 (0)