Skip to content

Commit 7365fa5

Browse files
committed
refactor: get_snapshot_group can identify latest~N snapshot
1 parent aca2b4c commit 7365fa5

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

crates/core/src/commands/snapshots.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `smapshot` subcommand
1+
//! `snapshot` subcommand
22
33
use crate::{
44
Progress,
@@ -22,6 +22,7 @@ use crate::{
2222
///
2323
/// * `repo` - The repository to get the snapshots from.
2424
/// * `ids` - The ids of the snapshots to get.
25+
/// * each `id` can use an actual (short) id "01a2b3c4" or "latest" or "latest~N"
2526
/// * `group_by` - The criterion to group the snapshots by.
2627
/// * `filter` - The filter to apply to the snapshots.
2728
///
@@ -37,25 +38,14 @@ pub(crate) fn get_snapshot_group<P: ProgressBars, S: Open>(
3738
let pb = &repo.pb;
3839
let dbe = repo.dbe();
3940
let p = pb.progress_counter("getting snapshots...");
40-
let groups = match ids {
41-
[] => SnapshotFile::group_from_backend(dbe, filter, group_by, &p)?,
42-
[id] if id == "latest" => SnapshotFile::group_from_backend(dbe, filter, group_by, &p)?
43-
.into_iter()
44-
.map(|(group, mut snaps)| {
45-
snaps.sort_unstable();
46-
let last_idx = snaps.len() - 1;
47-
snaps.swap(0, last_idx);
48-
snaps.truncate(1);
49-
(group, snaps)
50-
})
51-
.collect::<Vec<_>>(),
52-
_ => {
53-
let item = (
54-
SnapshotGroup::default(),
55-
SnapshotFile::from_ids(dbe, ids, &p)?,
56-
);
57-
vec![item]
58-
}
41+
let groups = if ids.is_empty() {
42+
SnapshotFile::group_from_backend(dbe, filter, group_by, &p)?
43+
} else {
44+
let item = (
45+
SnapshotGroup::default(),
46+
SnapshotFile::from_strs(dbe, ids, |_| true, &p)?,
47+
);
48+
vec![item]
5949
};
6050
p.finish();
6151

0 commit comments

Comments
 (0)