From: Rob Browning Date: Mon, 8 Feb 2021 04:02:27 +0000 (-0600) Subject: gc: convert to internal command X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae3d844f9eb6eff6a4a4b61e57f5359e420dccc2;p=bup.git gc: convert to internal command Signed-off-by: Rob Browning --- diff --git a/lib/bup/cmd/gc.py b/lib/bup/cmd/gc.py index 6c4ae37..e1b995a 100755 --- a/lib/bup/cmd/gc.py +++ b/lib/bup/cmd/gc.py @@ -1,26 +1,7 @@ -#!/bin/sh -"""": # -*-python-*- -# https://sourceware.org/bugzilla/show_bug.cgi?id=26034 -export "BUP_ARGV_0"="$0" -arg_i=1 -for arg in "$@"; do - export "BUP_ARGV_${arg_i}"="$arg" - shift - arg_i=$((arg_i + 1)) -done -# Here to end of preamble replaced during install -bup_python="$(dirname "$0")/../../../config/bin/python" || exit $? -exec "$bup_python" "$0" -""" -# end of bup preamble from __future__ import absolute_import -# Intentionally replace the dirname "$0" that python prepends -import os, sys -sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..' - -from bup import compat, git, options +from bup import git, options from bup.gc import bup_gc from bup.helpers import die_if_errors, handle_ctrl_c, log @@ -37,29 +18,28 @@ unsafe use the command even though it may be DANGEROUS # FIXME: server mode? # FIXME: make sure client handles server-side changes reasonably -handle_ctrl_c() - -o = options.Options(optspec) -opt, flags, extra = o.parse(compat.argv[1:]) +def main(argv): + o = options.Options(optspec) + opt, flags, extra = o.parse_bytes(argv[1:]) -if not opt.unsafe: - o.fatal('refusing to run dangerous, experimental command without --unsafe') + if not opt.unsafe: + o.fatal('refusing to run dangerous, experimental command without --unsafe') -if extra: - o.fatal('no positional parameters expected') + if extra: + o.fatal('no positional parameters expected') -if opt.threshold: - try: - opt.threshold = int(opt.threshold) - except ValueError: - o.fatal('threshold must be an integer percentage value') - if opt.threshold < 0 or opt.threshold > 100: - o.fatal('threshold must be an integer percentage value') + if opt.threshold: + try: + opt.threshold = int(opt.threshold) + except ValueError: + o.fatal('threshold must be an integer percentage value') + if opt.threshold < 0 or opt.threshold > 100: + o.fatal('threshold must be an integer percentage value') -git.check_repo_or_die() + git.check_repo_or_die() -bup_gc(threshold=opt.threshold, - compression=opt.compress, - verbosity=opt.verbose) + bup_gc(threshold=opt.threshold, + compression=opt.compress, + verbosity=opt.verbose) -die_if_errors() + die_if_errors() diff --git a/lib/cmd/bup b/lib/cmd/bup index 6277853..d2e3e10 100755 --- a/lib/cmd/bup +++ b/lib/cmd/bup @@ -187,6 +187,7 @@ if not subcmd_name: try: if subcmd_name not in (b'bloom', b'cat-file', + b'gc', b'help', b'index', b'join',