3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
10 from bup import options, git, vfs
11 from bup.helpers import chunkyreader, handle_ctrl_c, log, saved_errors
14 bup cat-file [--meta|--bupm] /branch/revision/[path]
16 meta print the target's metadata entry (decoded then reencoded) to stdout
17 bupm print the target directory's .bupm file directly to stdout
22 o = options.Options(optspec)
23 (opt, flags, extra) = o.parse(sys.argv[1:])
25 git.check_repo_or_die()
26 top = vfs.RefList(None)
29 o.fatal('must specify a target')
31 o.fatal('only one target file allowed')
32 if opt.bupm and opt.meta:
33 o.fatal('--meta and --bupm are incompatible')
37 if not re.match(r'/*[^/]+/[^/]+', target):
38 o.fatal("path %r doesn't include a branch and revision" % target)
41 n = top.lresolve(target)
42 except vfs.NodeError as e:
45 if isinstance(n, vfs.FakeSymlink):
46 # Source is actually /foo/what, i.e. a top-level commit
47 # like /foo/latest, which is a symlink to ../.commit/SHA.
49 target = n.dereference()
52 if not stat.S_ISDIR(n.mode):
53 o.fatal('%r is not a directory' % target)
54 mfile = n.metadata_file() # VFS file -- cannot close().
56 meta_stream = mfile.open()
57 sys.stdout.write(meta_stream.read())
59 sys.stdout.write(n.metadata().encode())
61 if stat.S_ISREG(n.mode):
62 for b in chunkyreader(n.open()):
65 o.fatal('%r is not a plain file' % target)
68 log('warning: %d errors encountered\n' % len(saved_errors))