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)
52 header = 'blob %d\0' % len(blob)
56 dir = '.git/objects/%s' % hex[0:2]
57 fn = '%s/%s' % (dir, hex[2:])
61 if e.errno != errno.EEXIST:
63 if not os.path.exists(fn):
64 #log('creating %s' % fn)
65 tfn = '%s.%d' % (fn, os.getpid())
67 z = zlib.compressobj(1)
68 f.write(z.compress(header))
69 f.write(z.compress(blob))
74 #log('exists %s' % fn)
81 start_time = time.time()
88 while blob or not eof:
89 if not eof and (buf.used() < BLOBSIZE*2 or not blob):
90 bnew = sys.stdin.read(1024*1024)
91 if not len(bnew): eof = 1
92 #log('got %d, total %d' % (len(bnew), buf.used()))
97 blob = buf.get(buf.used())
98 if not blob and buf.used() >= BLOBSIZE*8:
99 blob = buf.get(BLOBSIZE*4) # limit max blob size
100 if not blob and not eof:
105 #log('SPLIT @ %-8d size=%-8d (blobsize=%d)'
106 # % (ofs, len(blob), BLOBSIZE))
109 nv = (ofs + buf.used())/1000000
113 secs = time.time() - start_time
114 log('\n%.2fkbytes in %.2f secs = %.2f kbytes/sec'
115 % (ofs/1024., secs, ofs/1024./secs))
118 assert(BLOBSIZE >= 32)