3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import
11 from bup import options, git, vfs
12 from bup.compat import argv_bytes
13 from bup.helpers import chunkyreader, handle_ctrl_c, log, saved_errors
14 from bup.io import byte_stream
15 from bup.repo import LocalRepo
18 bup cat-file [--meta|--bupm] /branch/revision/[path]
20 meta print the target's metadata entry (decoded then reencoded) to stdout
21 bupm print the target directory's .bupm file directly to stdout
26 o = options.Options(optspec)
27 (opt, flags, extra) = o.parse(sys.argv[1:])
29 git.check_repo_or_die()
32 o.fatal('must specify a target')
34 o.fatal('only one target file allowed')
35 if opt.bupm and opt.meta:
36 o.fatal('--meta and --bupm are incompatible')
38 target = argv_bytes(extra[0])
40 if not re.match(br'/*[^/]+/[^/]+', target):
41 o.fatal("path %r doesn't include a branch and revision" % target)
44 resolved = vfs.resolve(repo, target, follow=False)
45 leaf_name, leaf_item = resolved[-1]
47 log('error: cannot access %r in %r\n'
48 % ('/'.join(name for name, item in resolved), path))
51 mode = vfs.item_mode(leaf_item)
54 out = byte_stream(sys.stdout)
57 if not stat.S_ISDIR(mode):
58 o.fatal('%r is not a directory' % target)
59 _, bupm_oid = vfs.tree_data_and_bupm(repo, leaf_item.oid)
61 with vfs.tree_data_reader(repo, bupm_oid) as meta_stream:
62 out.write(meta_stream.read())
64 augmented = vfs.augment_item_meta(repo, leaf_item, include_size=True)
65 out.write(augmented.meta.encode())
67 if stat.S_ISREG(mode):
68 with vfs.fopen(repo, leaf_item) as f:
69 for b in chunkyreader(f):
72 o.fatal('%r is not a plain file' % target)
75 log('warning: %d errors encountered\n' % len(saved_errors))