File tree Expand file tree Collapse file tree 4 files changed +61
-6
lines changed
Expand file tree Collapse file tree 4 files changed +61
-6
lines changed Original file line number Diff line number Diff line change 1010
1111- New ` conserve versions --utc ` option.
1212
13+ - New ` conserve versions --newest ` option (thanks to tkuestner@).
14+
1315## v0.6.10 2020-12-30
1416
1517### Features
Original file line number Diff line number Diff 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" ) ]
150+ newest : bool ,
148151 /// Show size of stored trees.
149152 #[ structopt( long, short = "z" , conflicts_with = "short" ) ]
150153 sizes : bool ,
@@ -357,15 +360,22 @@ impl Command {
357360 Command :: Versions {
358361 archive,
359362 short,
363+ newest,
360364 sizes,
361365 utc,
362366 } => {
363367 ui:: enable_progress ( false ) ;
364368 let archive = Archive :: open_path ( archive) ?;
365369 if * short {
366- output:: show_brief_version_list ( & archive, & mut stdout) ?;
370+ output:: show_brief_version_list ( & archive, * newest , & mut stdout) ?;
367371 } else {
368- output:: show_verbose_version_list ( & archive, * sizes, * utc, & mut stdout) ?;
372+ output:: show_verbose_version_list (
373+ & archive,
374+ * sizes,
375+ * utc,
376+ * newest,
377+ & mut stdout,
378+ ) ?;
369379 }
370380 }
371381 }
Original file line number Diff line number Diff line change @@ -20,8 +20,16 @@ use std::io::{BufWriter, Write};
2020
2121use crate :: * ;
2222
23- pub fn show_brief_version_list ( archive : & Archive , w : & mut dyn Write ) -> Result < ( ) > {
24- for band_id in archive. list_band_ids ( ) ? {
23+ pub fn show_brief_version_list (
24+ archive : & Archive ,
25+ newest_first : bool ,
26+ w : & mut dyn Write ,
27+ ) -> Result < ( ) > {
28+ let mut band_ids = archive. list_band_ids ( ) ?;
29+ if newest_first {
30+ band_ids. reverse ( ) ;
31+ }
32+ for band_id in band_ids {
2533 writeln ! ( w, "{}" , band_id) ?
2634 }
2735 Ok ( ( ) )
@@ -37,9 +45,14 @@ pub fn show_verbose_version_list(
3745 archive : & Archive ,
3846 show_sizes : bool ,
3947 utc_times : bool ,
48+ newest_first : bool ,
4049 w : & mut dyn Write ,
4150) -> Result < ( ) > {
42- for band_id in archive. list_band_ids ( ) ? {
51+ let mut band_ids = archive. list_band_ids ( ) ?;
52+ if newest_first {
53+ band_ids. reverse ( ) ;
54+ }
55+ for band_id in band_ids {
4356 let band = match Band :: open ( & archive, & band_id) {
4457 Ok ( band) => band,
4558 Err ( e) => {
@@ -63,7 +76,9 @@ pub fn show_verbose_version_list(
6376 let start_time_str = if utc_times {
6477 start_time. format ( crate :: TIMESTAMP_FORMAT )
6578 } else {
66- start_time. with_timezone ( & chrono:: Local ) . format ( crate :: TIMESTAMP_FORMAT )
79+ start_time
80+ . with_timezone ( & chrono:: Local )
81+ . format ( crate :: TIMESTAMP_FORMAT )
6782 } ;
6883 let duration_str = info
6984 . end_time
Original file line number Diff line number Diff line change @@ -485,3 +485,31 @@ fn size_exclude() {
485485 . success ( )
486486 . stdout ( "10\n " ) ;
487487}
488+
489+ #[ test]
490+ fn brief_versions_sort_recent_first ( ) {
491+ let af = ScratchArchive :: new ( ) ;
492+ af. store_two_versions ( ) ;
493+
494+ run_conserve ( )
495+ . args ( & [ "versions" , "--short" , "--newest" ] )
496+ . arg ( af. path ( ) )
497+ . assert ( )
498+ . success ( )
499+ . stderr ( predicate:: str:: is_empty ( ) )
500+ . stdout ( "b0001\n b0000\n " ) ;
501+ }
502+
503+ #[ test]
504+ fn verbose_versions_sort_recent_first ( ) {
505+ let af = ScratchArchive :: new ( ) ;
506+ af. store_two_versions ( ) ;
507+
508+ run_conserve ( )
509+ . args ( & [ "versions" , "--newest" ] )
510+ . arg ( af. path ( ) )
511+ . assert ( )
512+ . success ( )
513+ . stderr ( predicate:: str:: is_empty ( ) )
514+ . stdout ( predicate:: str:: is_match ( "b0001.*\n b0000.*" ) . unwrap ( ) ) ;
515+ }
You can’t perform that action at this time.
0 commit comments