1 #!/usr/bin/env python2.5
2 import sys, struct, mmap
7 def list_indexes(conn):
8 for f in os.listdir(git.repo('objects/pack')):
10 conn.write('%s\n' % f)
14 def send_index(conn, name):
15 assert(name.find('/') < 0)
16 assert(name.endswith('.idx'))
17 idx = git.PackIndex(git.repo('objects/pack/%s' % name))
18 conn.write(struct.pack('!I', len(idx.map)))
23 def receive_objects(conn):
29 raise Exception('object read: expected length header, got EOF\n')
30 n = struct.unpack('!I', ns)[0]
31 #log('expecting %d bytes\n' % n)
33 log('bup server: received %d object%s.\n'
34 % (w.count, w.count!=1 and "s" or ''))
37 buf = conn.read(n) # object sizes in bup are reasonably small
38 #log('read %d bytes\n' % n)
41 raise Exception('object read: expected %d bytes, got %d\n'
50 o = options.Options('bup server', optspec)
51 (opt, flags, extra) = o.parse(sys.argv[1:])
54 log('bup server: no arguments expected\n')
57 log('bup server: reading from stdin.\n')
59 # FIXME: this protocol is totally lame and not at all future-proof
60 conn = Conn(sys.stdin, sys.stdout)
66 log('bup server: command: %r\n' % line)
69 elif line.startswith('set-dir '):
70 git.repodir = line[8:]
71 git.check_repo_or_die()
72 log('bup server: bupdir is %r\n' % git.repodir)
74 elif line == 'list-indexes':
76 elif line.startswith('send-index '):
77 send_index(conn, line[11:])
78 elif line == 'receive-objects':
79 git.check_repo_or_die()
83 raise Exception('unknown server command: %r\n' % line)
85 log('bup server: done\n')