def test_encode(): s = b'hello world' looseb = b''.join(git._encode_looseobj(b'blob', s)) looset = b''.join(git._encode_looseobj(b'tree', s)) loosec = b''.join(git._encode_looseobj(b'commit', s)) packb = b''.join(git._encode_packobj(b'blob', s)) packt = b''.join(git._encode_packobj(b'tree', s)) packc = b''.join(git._encode_packobj(b'commit', s)) packlb = b''.join(git._encode_packobj(b'blob', s * 200)) WVPASSEQ(git._decode_looseobj(looseb), (b'blob', s)) WVPASSEQ(git._decode_looseobj(looset), (b'tree', s)) WVPASSEQ(git._decode_looseobj(loosec), (b'commit', s)) WVPASSEQ(git._decode_packobj(packb), (b'blob', s)) WVPASSEQ(git._decode_packobj(packt), (b'tree', s)) WVPASSEQ(git._decode_packobj(packc), (b'commit', s)) WVPASSEQ(git._decode_packobj(packlb), (b'blob', s * 200)) for i in range(10): WVPASS(git._encode_looseobj(b'blob', s, compression_level=i)) def encode_pobj(n): return b''.join(git._encode_packobj(b'blob', s, compression_level=n)) WVEXCEPT(ValueError, encode_pobj, -1) WVEXCEPT(ValueError, encode_pobj, 10) WVEXCEPT(ValueError, encode_pobj, b'x')
def testencode(): s = 'hello world' looseb = ''.join(git._encode_looseobj('blob', s)) looset = ''.join(git._encode_looseobj('tree', s)) loosec = ''.join(git._encode_looseobj('commit', s)) packb = ''.join(git._encode_packobj('blob', s)) packt = ''.join(git._encode_packobj('tree', s)) packc = ''.join(git._encode_packobj('commit', s)) WVPASSEQ(git._decode_looseobj(looseb), ('blob', s)) WVPASSEQ(git._decode_looseobj(looset), ('tree', s)) WVPASSEQ(git._decode_looseobj(loosec), ('commit', s)) WVPASSEQ(git._decode_packobj(packb), ('blob', s)) WVPASSEQ(git._decode_packobj(packt), ('tree', s)) WVPASSEQ(git._decode_packobj(packc), ('commit', s))
def testencode(): with no_lingering_errors(): s = 'hello world' looseb = ''.join(git._encode_looseobj('blob', s)) looset = ''.join(git._encode_looseobj('tree', s)) loosec = ''.join(git._encode_looseobj('commit', s)) packb = ''.join(git._encode_packobj('blob', s)) packt = ''.join(git._encode_packobj('tree', s)) packc = ''.join(git._encode_packobj('commit', s)) WVPASSEQ(git._decode_looseobj(looseb), ('blob', s)) WVPASSEQ(git._decode_looseobj(looset), ('tree', s)) WVPASSEQ(git._decode_looseobj(loosec), ('commit', s)) WVPASSEQ(git._decode_packobj(packb), ('blob', s)) WVPASSEQ(git._decode_packobj(packt), ('tree', s)) WVPASSEQ(git._decode_packobj(packc), ('commit', s)) for i in xrange(10): WVPASS(git._encode_looseobj('blob', s, compression_level=i)) def encode_pobj(n): return ''.join(git._encode_packobj('blob', s, compression_level=n)) WVEXCEPT(ValueError, encode_pobj, -1) WVEXCEPT(ValueError, encode_pobj, 10) WVEXCEPT(ValueError, encode_pobj, 'x')
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() if fullpath: (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) # FIXME: we only suggest a single index per cycle, because the client # is currently dumb to download more than one per cycle anyway. # Actually we should fix the client, but this is a minor optimization # on the server side. if not suggested and \ oldpack and (oldpack == True or oldpack.endswith('.midx')): # FIXME: we shouldn't really have to know about midx files # at this layer. But exists() on a midx doesn't return the # packname (since it doesn't know)... probably we should just # fix that deficiency of midx files eventually, although it'll # make the files bigger. This method is certainly not very # efficient. w.objcache.refresh(skip_midx = True) oldpack = w.objcache.exists(sha) log('new suggestion: %r\n' % oldpack) assert(oldpack) assert(oldpack != True) assert(not oldpack.endswith('.midx')) w.objcache.refresh(skip_midx = False) if not suggested and 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 decode_packobj(data): it = git._decode_packobj(data) tp, sz = next(it) return (tp, b''.join(it))