3 from bup import options, git, vfs
4 from bup.helpers import *
7 bup cat-file [--meta|--bupm] /branch/revision/[path]
9 meta print the target's metadata entry (decoded then reencoded) to stdout
10 bupm print the target directory's .bupm file directly to stdout
15 o = options.Options(optspec)
16 (opt, flags, extra) = o.parse(sys.argv[1:])
18 git.check_repo_or_die()
19 top = vfs.RefList(None)
22 o.fatal('must specify a target')
24 o.fatal('only one target file allowed')
25 if opt.bupm and opt.meta:
26 o.fatal('--meta and --bupm are incompatible')
30 if not re.match(r'/*[^/]+/[^/]+', target):
31 o.fatal("path %r doesn't include a branch and revision" % target)
34 n = top.lresolve(target)
35 except vfs.NodeError, e:
38 if isinstance(n, vfs.FakeSymlink):
39 # Source is actually /foo/what, i.e. a top-level commit
40 # like /foo/latest, which is a symlink to ../.commit/SHA.
42 target = n.dereference()
45 if not stat.S_ISDIR(n.mode):
46 o.fatal('%r is not a directory' % target)
47 mfile = n.metadata_file() # VFS file -- cannot close().
49 meta_stream = mfile.open()
50 sys.stdout.write(meta_stream.read())
52 sys.stdout.write(n.metadata().encode())
54 if stat.S_ISREG(n.mode):
55 for b in chunkyreader(n.open()):
58 o.fatal('%r is not a plain file' % target)
61 log('warning: %d errors encountered\n' % len(saved_errors))