395 current_size = f.tell() |
395 current_size = f.tell() |
396 if current_size < start: |
396 if current_size < start: |
397 start = 0 |
397 start = 0 |
398 if current_size != start: |
398 if current_size != start: |
399 threshold = current_size * REWRITE_RATIO |
399 threshold = current_size * REWRITE_RATIO |
400 if (max(end, current_size) - start) < threshold: |
400 overwritten = min(end, current_size) - start |
401 # end affected, let overwrite the bad value |
401 if (max(end, current_size) - start) >= threshold: |
402 overwritten = min(end, current_size) - start |
402 start = 0 |
|
403 dbg = b"resetting content of cache/%s\n" % _rbcrevs |
|
404 repo.ui.debug(dbg) |
|
405 elif overwritten > 0: |
|
406 # end affected, let us overwrite the bad value |
403 dbg = b"overwriting %d bytes from %d in cache/%s" |
407 dbg = b"overwriting %d bytes from %d in cache/%s" |
404 dbg %= (overwritten, start, _rbcrevs) |
408 dbg %= (current_size - start, start, _rbcrevs) |
405 if end < current_size: |
409 if end < current_size: |
406 extra = b" leaving (%d trailing bytes)" |
410 extra = b" leaving (%d trailing bytes)" |
407 extra %= current_size - end |
411 extra %= current_size - end |
408 dbg += extra |
412 dbg += extra |
409 dbg += b'\n' |
413 dbg += b'\n' |
410 repo.ui.debug(dbg) |
414 repo.ui.debug(dbg) |
411 else: |
415 else: |
412 start = 0 |
416 # extra untouched data at the end, lets warn about them |
413 dbg = b"resetting content of cache/%s\n" % _rbcrevs |
417 assert start == end # since don't write anything |
|
418 dbg = b"cache/%s contains %d unknown trailing bytes\n" |
|
419 dbg %= (_rbcrevs, current_size - start) |
414 repo.ui.debug(dbg) |
420 repo.ui.debug(dbg) |
|
421 |
415 if start > 0: |
422 if start > 0: |
416 f.seek(start) |
423 f.seek(start) |
417 f.write(self._rbcrevs.slice(start, end)) |
424 f.write(self._rbcrevs.slice(start, end)) |
418 else: |
425 else: |
419 f.close() |
426 f.close() |