]> arthur.barton.de Git - bup.git/commitdiff
gc: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Mon, 8 Feb 2021 04:02:27 +0000 (22:02 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:38 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/gc.py
lib/cmd/bup

index 6c4ae37ab0328a85a41234b179d97dc542e919bb..e1b995a3885afc56da9a1f46c5b533e5d15e49cd 100755 (executable)
@@ -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()
index 627785375981d266d286ff1e2d3a64fd2f2422b0..d2e3e102ea185873f5c0c2bf84fcee35a13201d2 100755 (executable)
@@ -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',