2 import sys, os, subprocess, errno, zlib, time
6 # FIXME: duplicated in C module. This shouldn't really be here at all...
8 BLOBSIZE = 1 << (BLOBBITS-1)
12 sys.stderr.write('%s\n' % s)
21 #log('oldsize=%d+%d adding=%d' % (len(self.data), self.start, len(s)))
23 self.data = buffer(self.data, self.start) + s
26 def peek(self, count):
27 return buffer(self.data, self.start, count)
33 v = buffer(self.data, self.start, count)
38 return len(self.data) - self.start
42 #return buf.get(BLOBSIZE)
43 b = buf.peek(buf.used())
44 ofs = hashsplit.splitbuf(b)
47 return buffer(b, 0, ofs)
53 header = 'blob %d\0' % len(blob)
57 dir = '.git/objects/%s' % hex[0:2]
58 fn = '%s/%s' % (dir, hex[2:])
59 if not ocache.get(hex) and not os.path.exists(fn):
60 #log('creating %s' % fn)
64 if e.errno != errno.EEXIST:
66 tfn = '%s.%d' % (fn, os.getpid())
68 z = zlib.compressobj(1)
69 f.write(z.compress(header))
70 f.write(z.compress(blob))
75 #log('exists %s' % fn)
83 start_time = time.time()
90 while blob or not eof:
91 if not eof and (buf.used() < BLOBSIZE*2 or not blob):
92 bnew = sys.stdin.read(1024*1024)
93 if not len(bnew): eof = 1
94 #log('got %d, total %d' % (len(bnew), buf.used()))
99 blob = buf.get(buf.used())
100 if not blob and buf.used() >= BLOBSIZE*8:
101 blob = buf.get(BLOBSIZE*4) # limit max blob size
102 if not blob and not eof:
107 #log('SPLIT @ %-8d size=%-8d (blobsize=%d)'
108 # % (ofs, len(blob), BLOBSIZE))
111 nv = (ofs + buf.used())/1000000
115 secs = time.time() - start_time
116 log('\n%.2fkbytes in %.2f secs = %.2f kbytes/sec'
117 % (ofs/1024., secs, ofs/1024./secs))
120 assert(BLOBSIZE >= 32)