3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from bup import options, git, vfs
9 from bup.helpers import *
12 bup cat-file [--meta|--bupm] /branch/revision/[path]
14 meta print the target's metadata entry (decoded then reencoded) to stdout
15 bupm print the target directory's .bupm file directly to stdout
20 o = options.Options(optspec)
21 (opt, flags, extra) = o.parse(sys.argv[1:])
23 git.check_repo_or_die()
24 top = vfs.RefList(None)
27 o.fatal('must specify a target')
29 o.fatal('only one target file allowed')
30 if opt.bupm and opt.meta:
31 o.fatal('--meta and --bupm are incompatible')
35 if not re.match(r'/*[^/]+/[^/]+', target):
36 o.fatal("path %r doesn't include a branch and revision" % target)
39 n = top.lresolve(target)
40 except vfs.NodeError as e:
43 if isinstance(n, vfs.FakeSymlink):
44 # Source is actually /foo/what, i.e. a top-level commit
45 # like /foo/latest, which is a symlink to ../.commit/SHA.
47 target = n.dereference()
50 if not stat.S_ISDIR(n.mode):
51 o.fatal('%r is not a directory' % target)
52 mfile = n.metadata_file() # VFS file -- cannot close().
54 meta_stream = mfile.open()
55 sys.stdout.write(meta_stream.read())
57 sys.stdout.write(n.metadata().encode())
59 if stat.S_ISREG(n.mode):
60 for b in chunkyreader(n.open()):
63 o.fatal('%r is not a plain file' % target)
66 log('warning: %d errors encountered\n' % len(saved_errors))