5 BLOBSIZE = 1 << (BLOBBITS-1)
7 WINDOWSIZE = 1 << (WINDOWBITS-1)
9 # FIXME: replace this with a not-stupid rolling checksum algorithm,
10 # such as the one used in rsync (Adler32?)
11 def stupidsum_add(old, drop, add):
12 return (((old<<1) | ((old>>31)&0xffffffff)) & 0xffffffff) ^ drop ^ add
17 for i in range(WINDOWSIZE):
18 sum = stupidsum_add(sum, 0, i%256)
20 for i in range(WINDOWSIZE*5):
21 sum = stupidsum_add(sum, i%256, i%256)
23 for i in range(WINDOWSIZE):
24 sum = stupidsum_add(sum, i%256, 0)
41 while count > 0 and self.list:
44 out.append(self.list[0])
45 self.list = self.list[1:]
48 out.append(self.list[0][:n])
49 self.list[0] = self.list[0][n:]
59 #return buf.get(BLOBSIZE)
60 window = [0] * WINDOWSIZE
68 sum = stupidsum_add(sum, window[i], b)
70 i = (i + 1) % WINDOWSIZE
71 if (sum & (BLOBSIZE-1)) == ((~0) & (BLOBSIZE-1)):
77 pipe = subprocess.Popen(['git', 'hash-object', '--stdin', '-w'],
78 stdin=subprocess.PIPE)
79 pipe.stdin.write(blob)
91 while blob or not eof:
92 if not eof and (buf.used() < BLOBSIZE*2 or not blob):
93 bnew = sys.stdin.read(BLOBSIZE*4)
94 if not len(bnew): eof = 1
95 # print 'got %d, total %d' % (len(bnew), buf.used())
99 if not blob and not eof:
102 blob = buf.get(buf.used())
106 sys.stderr.write('SPLIT @ %-8d size=%-8d (%d/%d)\n'
107 % (ofs, len(blob), BLOBSIZE, WINDOWSIZE))
110 assert(WINDOWSIZE >= 32)
111 assert(BLOBSIZE >= 32)