From a78fed9692af220b8e6fc5f3bce93e2f11f752ed Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 15 May 2011 16:03:39 -0400 Subject: [PATCH] cmd/{split,save}: support any compression level using the new -# feature. This makes the code *and* documentation a little nicer. Signed-off-by: Avery Pennarun --- Documentation/bup-save.md | 14 +++++--------- Documentation/bup-split.md | 13 +++++-------- cmd/save-cmd.py | 12 ++---------- cmd/split-cmd.py | 16 +++------------- lib/bup/git.py | 4 ++++ 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/Documentation/bup-save.md b/Documentation/bup-save.md index d8b9ca6..e895a2b 100644 --- a/Documentation/bup-save.md +++ b/Documentation/bup-save.md @@ -8,7 +8,7 @@ bup-save - create a new bup backup set # SYNOPSIS -bup save [-r *host*:*path*] <-t|-c|-n *name*> [-0|-9] [-f *indexfile*] +bup save [-r *host*:*path*] <-t|-c|-n *name*> [-#] [-f *indexfile*] [-v] [-q] [--smaller=*maxsize*] # DESCRIPTION @@ -100,15 +100,11 @@ for `bup-index`(1). "bup save -n chroots --graft /root/chroot/a/etc=/chroots/a" would be saved as */chroots/a/etc* --0 -: set the compression level to 0 (no compression) +-*#*, --compress=*#* +: set the compression level to # (a value from 0-9, where + 9 is the highest and 0 is no compression). The default + is 1 (fast, loose compression) - If no compression level is set it defaults to 1. - --9 -: set the compression level to 9 (highest compression, slowest) - - If no compression level is set it defaults to 1. # EXAMPLE diff --git a/Documentation/bup-split.md b/Documentation/bup-split.md index a85bca8..eba57ea 100644 --- a/Documentation/bup-split.md +++ b/Documentation/bup-split.md @@ -9,7 +9,7 @@ bup-split - save individual files to bup backup sets # SYNOPSIS bup split [-r *host*:*path*] <-b|-t|-c|-n *name*> [-v] [-q] - [--bench] [--max-pack-size=*bytes*] [-0|-9] + [--bench] [--max-pack-size=*bytes*] [-#] [--max-pack-objects=*n*] [--fanout=*count] [--git-ids] [--keep-boundaries] [filenames...] @@ -133,13 +133,10 @@ To get the data back, use `bup-join`(1). like k, M, or G to specify multiples of 1024, 1024*1024, 1024*1024*1024 respectively. --0 -: set the compression level to 0 (no compression) - - If no compression level is set it defaults to 1. - --9 -: set the compression level to 9 (highest compression, slowest) +-*#*, --compress=*#* +: set the compression level to # (a value from 0-9, where + 9 is the highest and 0 is no compression). The default + is 1 (fast, loose compression) # EXAMPLE diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index d8ab948..fb45427 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -21,8 +21,7 @@ f,indexfile= the name of the index file (normally BUP_DIR/bupindex) strip strips the path to every filename given strip-path= path-prefix to be stripped when saving graft= a graft point *old_path*=*new_path* (can be used more than once) -0 set compression-level to 0 -9 set compression-level to 9 +#,compress= set compression level to # (0-9, 9 is highest) [1] """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) @@ -33,13 +32,6 @@ if not (opt.tree or opt.commit or opt.name): if not extra: o.fatal("no filenames given") -if opt['0']: - compression_level = 0 -elif opt['9']: - compression_level = 9 -else: - compression_level = 1 - opt.progress = (istty2 and not opt.quiet) opt.smaller = parse_num(opt.smaller or 0) if opt.bwlimit: @@ -83,7 +75,7 @@ if opt.remote or is_reverse: else: cli = None oldref = refname and git.read_ref(refname) or None - w = git.PackWriter(compression_level=compression_level) + w = git.PackWriter(compression_level=opt.compress) handle_ctrl_c() diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py index b51f997..438fe40 100755 --- a/cmd/split-cmd.py +++ b/cmd/split-cmd.py @@ -26,8 +26,7 @@ max-pack-size= maximum bytes in a single pack max-pack-objects= maximum number of objects in a single pack fanout= maximum number of blobs in a single tree bwlimit= maximum bytes/sec to transmit to server -0 set compression-level to 0 -9 set compression-level to 9 +#,compress= set compression level to # (0-9, 9 is highest) [1] """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) @@ -63,15 +62,6 @@ if opt.date: else: date = time.time() -if opt['0']: - compression_level = 0 -elif opt['9']: - compression_level = 9 -else: - compression_level = 1 - - - total_bytes = 0 def prog(filenum, nbytes): global total_bytes @@ -94,13 +84,13 @@ refname = opt.name and 'refs/heads/%s' % opt.name or None if opt.noop or opt.copy: cli = pack_writer = oldref = None elif opt.remote or is_reverse: - cli = client.Client(opt.remote, compression_level = compression_level) + cli = client.Client(opt.remote, compression_level=opt.compress) oldref = refname and cli.read_ref(refname) or None pack_writer = cli.new_packwriter() else: cli = None oldref = refname and git.read_ref(refname) or None - pack_writer = git.PackWriter(compression_level = compression_level) + pack_writer = git.PackWriter(compression_level=opt.compress) if opt.git_ids: # the input is actually a series of git object ids that we should retrieve diff --git a/lib/bup/git.py b/lib/bup/git.py index 2a84eeb..58cd4a6 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -177,6 +177,10 @@ def _encode_packobj(type, content, compression_level=1): break szbits = sz & 0x7f sz >>= 7 + if compression_level > 9: + compression_level = 9 + elif compression_level < 0: + compression_level = 0 z = zlib.compressobj(compression_level) yield szout yield z.compress(content) -- 2.39.2