Show More
@@ -17,6 +17,7 b' import binascii' | |||
|
17 | 17 | import collections |
|
18 | 18 | import errno |
|
19 | 19 | import hashlib |
|
20 | import heapq | |
|
20 | 21 | import os |
|
21 | 22 | import struct |
|
22 | 23 | import zlib |
@@ -170,49 +171,59 b' def _slicechunk(revlog, revs):' | |||
|
170 | 171 | start = revlog.start |
|
171 | 172 | length = revlog.length |
|
172 | 173 | |
|
173 | chunkqueue = collections.deque() | |
|
174 | chunkqueue.append((revs, 0)) | |
|
175 | ||
|
176 | while chunkqueue: | |
|
177 | revs, depth = chunkqueue.popleft() | |
|
174 | if len(revs) <= 1: | |
|
175 | yield revs | |
|
176 | return | |
|
178 | 177 | |
|
179 | 178 |
|
|
180 | 179 |
|
|
181 |
|
|
|
180 | readdata = deltachainspan = endbyte - startbyte | |
|
182 | 181 | |
|
183 | if deltachainspan <= revlog._srminblocksize or len(revs) <= 1: | |
|
184 | yield revs | |
|
185 | continue | |
|
182 | chainpayload = sum(length(r) for r in revs) | |
|
186 | 183 | |
|
187 | # Find where is the largest hole (this is where we would split) and | |
|
188 | # sum up the lengths of useful data to compute the density of the span | |
|
189 | textlen = 0 | |
|
184 | if deltachainspan: | |
|
185 | density = chainpayload / float(deltachainspan) | |
|
186 | else: | |
|
187 | density = 1.0 | |
|
188 | ||
|
189 | # Store the gaps in a heap to have them sorted by decreasing size | |
|
190 | gapsheap = [] | |
|
191 | heapq.heapify(gapsheap) | |
|
190 | 192 |
|
|
191 | largesthole = 0 | |
|
192 | idxlargesthole = -1 | |
|
193 | 193 |
|
|
194 | 194 |
|
|
195 | 195 |
|
|
196 | 196 | |
|
197 | 197 |
|
|
198 |
|
|
|
199 |
|
|
|
200 | largesthole = hole | |
|
201 | idxlargesthole = i | |
|
198 | gapsize = revstart - prevend | |
|
199 | if gapsize: | |
|
200 | heapq.heappush(gapsheap, (-gapsize, i)) | |
|
202 | 201 | |
|
203 | textlen += revlen | |
|
204 | 202 |
|
|
205 | 203 | |
|
206 | density = textlen / float(deltachainspan) if deltachainspan > 0 else 1.0 | |
|
204 | # Collect the indices of the largest holes until the density is acceptable | |
|
205 | indicesheap = [] | |
|
206 | heapq.heapify(indicesheap) | |
|
207 | while gapsheap and density < revlog._srdensitythreshold: | |
|
208 | oppgapsize, gapidx = heapq.heappop(gapsheap) | |
|
209 | ||
|
210 | heapq.heappush(indicesheap, gapidx) | |
|
207 | 211 | |
|
208 | if density > revlog._srdensitythreshold: | |
|
209 | yield revs | |
|
210 | continue | |
|
212 | # the gap sizes are stored as negatives to be sorted decreasingly | |
|
213 | # by the heap | |
|
214 | readdata -= (-oppgapsize) | |
|
215 | if readdata > 0: | |
|
216 | density = chainpayload / float(readdata) | |
|
217 | else: | |
|
218 | density = 1.0 | |
|
211 | 219 | |
|
212 | # Add the left and right parts so that they will be sliced | |
|
213 | # recursively too | |
|
214 | chunkqueue.append((revs[:idxlargesthole], depth + 1)) | |
|
215 | chunkqueue.append((revs[idxlargesthole:], depth + 1)) | |
|
220 | # Cut the revs at collected indices | |
|
221 | previdx = 0 | |
|
222 | while indicesheap: | |
|
223 | idx = heapq.heappop(indicesheap) | |
|
224 | yield revs[previdx:idx] | |
|
225 | previdx = idx | |
|
226 | yield revs[previdx:] | |
|
216 | 227 | |
|
217 | 228 | # index v0: |
|
218 | 229 | # 4 bytes: offset |
General Comments 0
You need to be logged in to leave comments.
Login now