Show More
@@ -15,6 +15,7 b' from __future__ import absolute_import' | |||||
15 |
|
15 | |||
16 | import binascii |
|
16 | import binascii | |
17 | import collections |
|
17 | import collections | |
|
18 | import contextlib | |||
18 | import errno |
|
19 | import errno | |
19 | import hashlib |
|
20 | import hashlib | |
20 | import heapq |
|
21 | import heapq | |
@@ -694,6 +695,19 b' class revlog(object):' | |||||
694 | """file object for the revlog's data file""" |
|
695 | """file object for the revlog's data file""" | |
695 | return self.opener(self.datafile, mode=mode) |
|
696 | return self.opener(self.datafile, mode=mode) | |
696 |
|
697 | |||
|
698 | @contextlib.contextmanager | |||
|
699 | def _datareadfp(self, existingfp=None): | |||
|
700 | """file object suitable to read data""" | |||
|
701 | if existingfp is not None: | |||
|
702 | yield existingfp | |||
|
703 | else: | |||
|
704 | if self._inline: | |||
|
705 | func = self._indexfp | |||
|
706 | else: | |||
|
707 | func = self._datafp | |||
|
708 | with func() as fp: | |||
|
709 | yield fp | |||
|
710 | ||||
697 | def tip(self): |
|
711 | def tip(self): | |
698 | return self.node(len(self.index) - 2) |
|
712 | return self.node(len(self.index) - 2) | |
699 | def __contains__(self, rev): |
|
713 | def __contains__(self, rev): | |
@@ -1502,15 +1516,6 b' class revlog(object):' | |||||
1502 |
|
1516 | |||
1503 | Returns a str or buffer of raw byte data. |
|
1517 | Returns a str or buffer of raw byte data. | |
1504 | """ |
|
1518 | """ | |
1505 | if df is not None: |
|
|||
1506 | closehandle = False |
|
|||
1507 | else: |
|
|||
1508 | if self._inline: |
|
|||
1509 | df = self._indexfp() |
|
|||
1510 | else: |
|
|||
1511 | df = self._datafp() |
|
|||
1512 | closehandle = True |
|
|||
1513 |
|
||||
1514 | # Cache data both forward and backward around the requested |
|
1519 | # Cache data both forward and backward around the requested | |
1515 | # data, in a fixed size window. This helps speed up operations |
|
1520 | # data, in a fixed size window. This helps speed up operations | |
1516 | # involving reading the revlog backwards. |
|
1521 | # involving reading the revlog backwards. | |
@@ -1518,10 +1523,9 b' class revlog(object):' | |||||
1518 | realoffset = offset & ~(cachesize - 1) |
|
1523 | realoffset = offset & ~(cachesize - 1) | |
1519 | reallength = (((offset + length + cachesize) & ~(cachesize - 1)) |
|
1524 | reallength = (((offset + length + cachesize) & ~(cachesize - 1)) | |
1520 | - realoffset) |
|
1525 | - realoffset) | |
1521 | df.seek(realoffset) |
|
1526 | with self._datareadfp(df) as df: | |
1522 |
|
|
1527 | df.seek(realoffset) | |
1523 | if closehandle: |
|
1528 | d = df.read(reallength) | |
1524 | df.close() |
|
|||
1525 | self._cachesegment(realoffset, d) |
|
1529 | self._cachesegment(realoffset, d) | |
1526 | if offset != realoffset or reallength != length: |
|
1530 | if offset != realoffset or reallength != length: | |
1527 | return util.buffer(d, offset - realoffset, length) |
|
1531 | return util.buffer(d, offset - realoffset, length) |
General Comments 0
You need to be logged in to leave comments.
Login now