2 from __future__ import absolute_import, print_function
3 from binascii import hexlify, unhexlify
6 from bup import git, options
7 from bup.compat import argv_bytes
8 from bup.helpers import add_error, handle_ctrl_c, log, qprogress, saved_errors
9 from bup.io import byte_stream
12 bup list-idx [--find=<prefix>] <idxfilenames...>
14 find= display only objects that start with <prefix>
18 o = options.Options(optspec)
19 opt, flags, extra = o.parse_bytes(argv[1:])
23 opt.find = argv_bytes(opt.find) if opt.find else b''
26 o.fatal('you must provide at least one filename')
28 if len(opt.find) > 40:
29 o.fatal('--find parameter must be <= 40 chars long')
38 o.fatal('--find parameter is not a valid hex string')
41 out = byte_stream(sys.stdout)
42 find = opt.find.lower()
44 idxfiles = [argv_bytes(x) for x in extra]
47 ix = git.open_idx(name)
48 except git.GitError as e:
49 add_error('%r: %s' % (name, e))
53 if len(opt.find) == 40:
55 out.write(b'%s %s\n' % (name, find))
57 # slow, exhaustive search
60 if i.startswith(find):
61 out.write(b'%s %s\n' % (name, i))
62 qprogress('Searching: %d\r' % count)
66 log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))