]> arthur.barton.de Git - bup.git/blobdiff - t/subtree-hash
Client.read_ref: replace encode with hexlify
[bup.git] / t / subtree-hash
index 94cd3b36d1f7e77c59a57fd344dbd1fd79132b53..062f4858be60cfe65e521143415f1da338df67b2 100755 (executable)
@@ -1,19 +1,36 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
 
-from subprocess import check_output
-import argparse
-import sys
+from __future__ import absolute_import
+import os, sys
 
-parser = argparse.ArgumentParser()
-parser.add_argument("ROOT_HASH", help="root tree for the search")
-parser.add_argument("PATH_ITEM", help="path component", nargs='*')
-opts = parser.parse_args()
-tree_hash = opts.ROOT_HASH
-path = opts.PATH_ITEM
+from bup.helpers import handle_ctrl_c, readpipe
+from bup import options
+
+
+optspec = """
+subtree-hash ROOT_HASH [PATH_ITEM...]
+--
+"""
+
+handle_ctrl_c()
+
+o = options.Options(optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+if len(extra) < 1:
+    o.fatal('must specify a root hash')
+
+tree_hash = extra[0]
+path = extra[1:]
 
 while path:
     target_name = path[0]
-    subtree_items = check_output(['git', 'ls-tree', '-z', tree_hash])
+    subtree_items = readpipe(['git', 'ls-tree', '-z', tree_hash])
     target_hash = None
     for entry in subtree_items.split('\0'):
         if not entry: