]> arthur.barton.de Git - bup.git/commitdiff
list-idx: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Fri, 12 Feb 2021 20:02:46 +0000 (14:02 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:39 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/list_idx.py
lib/cmd/bup

index 6be50887efde3c758aac8474359ccb4d4eeb4275..8bf940ef88a3d02f8bc4ec185dd4bb5b8137de92 100755 (executable)
@@ -1,28 +1,9 @@
-#!/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, print_function
-
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
 from binascii import hexlify, unhexlify
+import os, sys
 
-from bup import compat, git, options
+from bup import git, options
 from bup.compat import argv_bytes
 from bup.helpers import add_error, handle_ctrl_c, log, qprogress, saved_errors
 from bup.io import byte_stream
@@ -32,51 +13,53 @@ bup list-idx [--find=<prefix>] <idxfilenames...>
 --
 find=   display only objects that start with <prefix>
 """
-o = options.Options(optspec)
-opt, flags, extra = o.parse(compat.argv[1:])
 
-handle_ctrl_c()
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
 
-opt.find = argv_bytes(opt.find) if opt.find else b''
+    handle_ctrl_c()
 
-if not extra:
-    o.fatal('you must provide at least one filename')
+    opt.find = argv_bytes(opt.find) if opt.find else b''
 
-if len(opt.find) > 40:
-    o.fatal('--find parameter must be <= 40 chars long')
-else:
-    if len(opt.find) % 2:
-        s = opt.find + b'0'
-    else:
-        s = opt.find
-    try:
-        bin = unhexlify(s)
-    except TypeError:
-        o.fatal('--find parameter is not a valid hex string')
+    if not extra:
+        o.fatal('you must provide at least one filename')
 
-sys.stdout.flush()
-out = byte_stream(sys.stdout)
-find = opt.find.lower()
-count = 0
-idxfiles = [argv_bytes(x) for x in extra]
-for name in idxfiles:
-    try:
-        ix = git.open_idx(name)
-    except git.GitError as e:
-        add_error('%r: %s' % (name, e))
-        continue
-    if len(opt.find) == 40:
-        if ix.exists(bin):
-            out.write(b'%s %s\n' % (name, find))
+    if len(opt.find) > 40:
+        o.fatal('--find parameter must be <= 40 chars long')
     else:
-        # slow, exhaustive search
-        for _i in ix:
-            i = hexlify(_i)
-            if i.startswith(find):
-                out.write(b'%s %s\n' % (name, i))
-            qprogress('Searching: %d\r' % count)
-            count += 1
+        if len(opt.find) % 2:
+            s = opt.find + b'0'
+        else:
+            s = opt.find
+        try:
+            bin = unhexlify(s)
+        except TypeError:
+            o.fatal('--find parameter is not a valid hex string')
+
+    sys.stdout.flush()
+    out = byte_stream(sys.stdout)
+    find = opt.find.lower()
+    count = 0
+    idxfiles = [argv_bytes(x) for x in extra]
+    for name in idxfiles:
+        try:
+            ix = git.open_idx(name)
+        except git.GitError as e:
+            add_error('%r: %s' % (name, e))
+            continue
+        if len(opt.find) == 40:
+            if ix.exists(bin):
+                out.write(b'%s %s\n' % (name, find))
+        else:
+            # slow, exhaustive search
+            for _i in ix:
+                i = hexlify(_i)
+                if i.startswith(find):
+                    out.write(b'%s %s\n' % (name, i))
+                qprogress('Searching: %d\r' % count)
+                count += 1
 
-if saved_errors:
-    log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))
-    sys.exit(1)
+    if saved_errors:
+        log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))
+        sys.exit(1)
index f3a82c93821c2cd2fc74672e1b812ee86e9890ba..aacb20b139b6b36e24ec820867a6241e03044ba9 100755 (executable)
@@ -197,6 +197,7 @@ try:
                            b'index',
                            b'init',
                            b'join',
+                           b'list-idx',
                            b'ls',
                            b'margin',
                            b'memtest',