def cat(conn, id): git.check_repo_or_die() for blob in git.cat(id): conn.write(struct.pack('!I', len(blob))) conn.write(blob) conn.write('\0\0\0\0') conn.ok()
def send_index(conn, name): git.check_repo_or_die() assert(name.find('/') < 0) assert(name.endswith('.idx')) idx = git.PackIndex(git.repo('objects/pack/%s' % name)) conn.write(struct.pack('!I', len(idx.map))) conn.write(idx.map) conn.ok()
def receive_objects(conn, junk): global suspended_w git.check_repo_or_die() suggested = {} if suspended_w: w = suspended_w suspended_w = None else: w = git.PackWriter() while 1: ns = conn.read(4) if not ns: w.abort() raise Exception('object read: expected length header, got EOF\n') n = struct.unpack('!I', ns)[0] #log('expecting %d bytes\n' % n) if not n: log('bup server: received %d object%s.\n' % (w.count, w.count!=1 and "s" or '')) fullpath = w.close() (dir, name) = os.path.split(fullpath) conn.write('%s.idx\n' % name) conn.ok() return elif n == 0xffffffff: log('bup server: receive-objects suspended.\n') suspended_w = w conn.ok() return buf = conn.read(n) # object sizes in bup are reasonably small #log('read %d bytes\n' % n) if len(buf) < n: w.abort() raise Exception('object read: expected %d bytes, got %d\n' % (n, len(buf))) (type, content) = git._decode_packobj(buf) sha = git.calc_hash(type, content) oldpack = w.exists(sha) if oldpack: assert(oldpack.endswith('.idx')) (dir,name) = os.path.split(oldpack) if not (name in suggested): log("bup server: suggesting index %s\n" % name) conn.write('index %s\n' % name) suggested[name] = 1 else: w._raw_write([buf])
def receive_objects(conn, junk): git.check_repo_or_die() w = git.PackWriter() while 1: ns = conn.read(4) if not ns: w.abort() raise Exception('object read: expected length header, got EOF\n') n = struct.unpack('!I', ns)[0] #log('expecting %d bytes\n' % n) if not n: log('bup server: received %d object%s.\n' % (w.count, w.count!=1 and "s" or '')) w.close() return buf = conn.read(n) # object sizes in bup are reasonably small #log('read %d bytes\n' % n) if len(buf) < n: w.abort() raise Exception('object read: expected %d bytes, got %d\n' % (n, len(buf))) w._raw_write(buf) w.close() conn.ok()
#!/usr/bin/env python import git, options, client from helpers import * optspec = """ [BUP_DIR=...] bup init [-r host:path] -- r,remote= remote repository path """ o = options.Options('bup init', optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if extra: log("bup init: no arguments expected\n") o.usage() if opt.remote: git.init_repo() # local repo git.check_repo_or_die() cli = client.Client(opt.remote, create=True) cli.close() else: git.init_repo()
def update_ref(conn, refname): git.check_repo_or_die() newval = conn.readline().strip() oldval = conn.readline().strip() git.update_ref(refname, newval.decode('hex'), oldval.decode('hex')) conn.ok()
def read_ref(conn, refname): git.check_repo_or_die() r = git.read_ref(refname) conn.write('%s\n' % (r or '').encode('hex')) conn.ok()
def list_indexes(conn, junk): git.check_repo_or_die() for f in os.listdir(git.repo('objects/pack')): if f.endswith('.idx'): conn.write('%s\n' % f) conn.ok()
def set_dir(conn, arg): git.check_repo_or_die(arg) log('bup server: bupdir is %r\n' % git.repodir) conn.ok()