]> arthur.barton.de Git - bup.git/commitdiff
cmd/list-idx: a quick tool for searching the contents of idx/midx files.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 12:50:04 +0000 (04:50 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 12:50:28 +0000 (04:50 -0800)
Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/list-idx-cmd.py [new file with mode: 0755]

diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py
new file mode 100755 (executable)
index 0000000..a3e3dc9
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+import sys, os
+from bup import git, options
+from bup.helpers import *
+
+optspec = """
+bup list-idx [--find=<prefix>] <idxfilenames...>
+--
+find=   display only objects that start with <prefix>
+"""
+o = options.Options(optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+handle_ctrl_c()
+opt.find = opt.find or ''
+
+if not extra:
+    o.fatal('you must provide at least one filename')
+
+if len(opt.find) > 40:
+    o.fatal('--find parameter must be <= 40 chars long')
+else:
+    if len(opt.find) % 2:
+        s = opt.find + '0'
+    else:
+        s = opt.find
+    try:
+        bin = s.decode('hex')
+    except TypeError:
+        o.fatal('--find parameter is not a valid hex string')
+
+find = opt.find.lower()
+
+count = 0
+for name in extra:
+    try:
+        ix = git.open_idx(name)
+    except git.GitError, e:
+        add_error('%s: %s' % (name, e))
+        continue
+    if len(opt.find) == 40:
+        if ix.exists(bin):
+            print name, find
+    else:
+        # slow, exhaustive search
+        for _i in ix:
+            i = str(_i).encode('hex')
+            if i.startswith(find):
+                print 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)