3 bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import, print_function
11 from bup.compat import argv_bytes
12 from bup.helpers import handle_ctrl_c, readpipe
13 from bup.io import byte_stream
14 from bup import options
18 subtree-hash ROOT_HASH [PATH_ITEM...]
24 o = options.Options(optspec)
25 (opt, flags, extra) = o.parse(sys.argv[1:])
28 o.fatal('must specify a root hash')
30 tree_hash = argv_bytes(extra[0])
31 path = [argv_bytes(x) for x in extra[1:]]
35 subtree_items = readpipe([b'git', b'ls-tree', b'-z', tree_hash])
37 for entry in subtree_items.split(b'\0'):
40 info, name = entry.split(b'\t', 1)
41 if name == target_name:
42 _, _, target_hash = info.split(b' ')
45 print("Can't find %r in %s" % (target_name, tree_hash.decode('ascii')),
48 tree_hash = target_hash
55 out = byte_stream(sys.stdout)
56 out.write(tree_hash + b'\n')