Skip to content

Commit 5ddd406

Browse files
author
tkuestner
committed
Implement option for 'conserve versions' to sort bands by start time.
Parameter '--newest' shows most recent band first. Fixes #121
1 parent 4738578 commit 5ddd406

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/bin/conserve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ enum Command {
145145
/// Show only version names.
146146
#[structopt(long, short = "q")]
147147
short: bool,
148+
/// Sort bands to show most recent first.
149+
#[structopt(long, short = "n", conflicts_with = "short" )]
150+
newest: bool,
148151
/// Show size of stored trees.
149152
#[structopt(long, short = "z", conflicts_with = "short")]
150153
sizes: bool,
@@ -354,14 +357,15 @@ impl Command {
354357
Command::Versions {
355358
archive,
356359
short,
360+
newest,
357361
sizes,
358362
} => {
359363
ui::enable_progress(false);
360364
let archive = Archive::open_path(archive)?;
361365
if *short {
362366
output::show_brief_version_list(&archive, &mut stdout)?;
363367
} else {
364-
output::show_verbose_version_list(&archive, *sizes, &mut stdout)?;
368+
output::show_verbose_version_list(&archive, *newest,*sizes, &mut stdout)?;
365369
}
366370
}
367371
}

src/output.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ pub fn show_brief_version_list(archive: &Archive, w: &mut dyn Write) -> Result<(
3131

3232
pub fn show_verbose_version_list(
3333
archive: &Archive,
34+
sort_recent_first: bool,
3435
show_sizes: bool,
3536
w: &mut dyn Write,
3637
) -> Result<()> {
38+
let mut band_infos = vec![];
3739
for band_id in archive.list_band_ids()? {
3840
let band = match Band::open(&archive, &band_id) {
3941
Ok(band) => band,
@@ -49,6 +51,14 @@ pub fn show_verbose_version_list(
4951
continue;
5052
}
5153
};
54+
band_infos.push(info);
55+
}
56+
if sort_recent_first {
57+
band_infos.sort_unstable_by_key(|info| std::cmp::Reverse(info.start_time));
58+
}
59+
60+
for info in band_infos {
61+
let band_id = &info.id;
5262
let is_complete_str = if info.is_closed {
5363
"complete"
5464
} else {

0 commit comments

Comments
 (0)