Repository: borgbackup/borg

Issue:
add --list option to prune
Right now invoking prune stats with `--stats --verbose` also inevitably lists all existing archives (Keeping.../Pruning...). I suggest to list them only when using a new --list option. This would bring prune in line with how `borg create --list` works while omitting it would emit compact prune stats only. Previous discussion in #526.



Discussion:
Sounds reasonable.


Resolving patch:
diff --git a/borg/archiver.py b/borg/archiver.py
--- a/borg/archiver.py
+++ b/borg/archiver.py
@@ -528,12 +528,15 @@ def do_prune(self, args):
         stats = Statistics()
         with Cache(repository, key, manifest, do_files=args.cache_files, lock_wait=self.lock_wait) as cache:
             for archive in keep:
-                logger.info('Keeping archive: %s' % format_archive(archive))
+                if args.output_list:
+                    logger.info('Keeping archive: %s' % format_archive(archive))
             for archive in to_delete:
                 if args.dry_run:
-                    logger.info('Would prune:     %s' % format_archive(archive))
+                    if args.output_list:
+                        logger.info('Would prune:     %s' % format_archive(archive))
                 else:
-                    logger.info('Pruning archive: %s' % format_archive(archive))
+                    if args.output_list:
+                        logger.info('Pruning archive: %s' % format_archive(archive))
                     Archive(repository, key, manifest, archive.name, cache).delete(stats)
             if to_delete and not args.dry_run:
                 manifest.write()
@@ -1184,6 +1187,9 @@ def build_parser(self, args=None, prog=None):
         subparser.add_argument('-s', '--stats', dest='stats',
                                action='store_true', default=False,
                                help='print statistics for the deleted archive')
+        subparser.add_argument('--list', dest='output_list',
+                               action='store_true', default=False,
+                               help='output verbose list of archives it keeps/prunes')
         subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN',
                                help='keep all archives within this time interval')
         subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0,
diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py
--- a/borg/testsuite/archiver.py
+++ b/borg/testsuite/archiver.py
@@ -835,7 +835,7 @@ def test_prune_repository(self):
         self.cmd('init', self.repository_location)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Would prune:     test1', output)
         output = self.cmd('list', self.repository_location)
@@ -850,7 +850,7 @@ def test_prune_repository_save_space(self):
         self.cmd('init', self.repository_location)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Would prune:     test1', output)
         output = self.cmd('list', self.repository_location)
@@ -867,7 +867,7 @@ def test_prune_repository_prefix(self):
         self.cmd('create', self.repository_location + '::foo-2015-08-12-20:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-10:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-20:00', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-')
         self.assert_in('Keeping archive: foo-2015-08-12-20:00', output)
         self.assert_in('Would prune:     foo-2015-08-12-10:00', output)
         output = self.cmd('list', self.repository_location)


Test patch: