X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fjoin-cmd.py;h=48bebe882f1c572f10d8d9ae015a8826d45873ea;hb=093752b42c5548028c6f84c67f7741b2321c512f;hp=d2cc888cd3020a4404f62aaf37950d848d64077e;hpb=c135a5834a9bf9cd9c3382d6489f93e3fdabeafd;p=bup.git diff --git a/cmd/join-cmd.py b/cmd/join-cmd.py index d2cc888..48bebe8 100755 --- a/cmd/join-cmd.py +++ b/cmd/join-cmd.py @@ -1,42 +1,53 @@ -#!/usr/bin/env python +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + +from __future__ import absolute_import import sys -from bup import git, options, client -from bup.helpers import * + +from bup import git, options +from bup.compat import argv_bytes +from bup.helpers import linereader, log +from bup.io import byte_stream +from bup.repo import LocalRepo, RemoteRepo optspec = """ bup join [-r host:path] [refs or hashes...] -- r,remote= remote repository path +o= output filename """ -o = options.Options('bup join', optspec) +o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) +if opt.remote: + opt.remote = argv_bytes(opt.remote) git.check_repo_or_die() +stdin = byte_stream(sys.stdin) + if not extra: - extra = linereader(sys.stdin) + extra = linereader(stdin) ret = 0 +repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo() -if opt.remote: - if opt.remote and opt.remote.find(":") == -1: - o.fatal("--remote argument must contain a colon") - try: - cli = client.Client(opt.remote) - except client.ClientError: - o.fatal("server exited unexpectedly; see errors above") - cat = cli.cat +if opt.o: + outfile = open(opt.o, 'wb') else: - cp = git.CatPipe() - cat = cp.join + sys.stdout.flush() + outfile = byte_stream(sys.stdout) -for id in extra: +for ref in [argv_bytes(x) for x in extra]: try: - for blob in cat(id): - sys.stdout.write(blob) - except KeyError, e: - sys.stdout.flush() + for blob in repo.join(ref): + outfile.write(blob) + except KeyError as e: + outfile.flush() log('error: %s\n' % e) ret = 1