Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 40053:55db747a21ad
revlog: rename _cache to _revisioncache
"cache" is generic and revlog instances have multiple caches. Let's
be descriptive about what this is a cache for.
Differential Revision: https://phab.mercurial-scm.org/D4866
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 03 Oct 2018 10:32:21 -0700 |
parents | f5d819d84461 |
children | 801ccd8e67c0 |
comparison
equal
deleted
inserted
replaced
40052:cdf61ab1f54c | 40053:55db747a21ad |
---|---|
344 # When True, indexfile is opened with checkambig=True at writing, to | 344 # When True, indexfile is opened with checkambig=True at writing, to |
345 # avoid file stat ambiguity. | 345 # avoid file stat ambiguity. |
346 self._checkambig = checkambig | 346 self._checkambig = checkambig |
347 self._censorable = censorable | 347 self._censorable = censorable |
348 # 3-tuple of (node, rev, text) for a raw revision. | 348 # 3-tuple of (node, rev, text) for a raw revision. |
349 self._cache = None | 349 self._revisioncache = None |
350 # Maps rev to chain base rev. | 350 # Maps rev to chain base rev. |
351 self._chainbasecache = util.lrucachedict(100) | 351 self._chainbasecache = util.lrucachedict(100) |
352 # 2-tuple of (offset, data) of raw data from the revlog at an offset. | 352 # 2-tuple of (offset, data) of raw data from the revlog at an offset. |
353 self._chunkcache = (0, '') | 353 self._chunkcache = (0, '') |
354 # How much data to read and cache into the raw revlog data cache. | 354 # How much data to read and cache into the raw revlog data cache. |
543 or (self.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS)): | 543 or (self.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS)): |
544 return False | 544 return False |
545 return True | 545 return True |
546 | 546 |
547 def clearcaches(self): | 547 def clearcaches(self): |
548 self._cache = None | 548 self._revisioncache = None |
549 self._chainbasecache.clear() | 549 self._chainbasecache.clear() |
550 self._chunkcache = (0, '') | 550 self._chunkcache = (0, '') |
551 self._pcache = {} | 551 self._pcache = {} |
552 | 552 |
553 try: | 553 try: |
1522 cachedrev = None | 1522 cachedrev = None |
1523 flags = None | 1523 flags = None |
1524 rawtext = None | 1524 rawtext = None |
1525 if node == nullid: | 1525 if node == nullid: |
1526 return "" | 1526 return "" |
1527 if self._cache: | 1527 if self._revisioncache: |
1528 if self._cache[0] == node: | 1528 if self._revisioncache[0] == node: |
1529 # _cache only stores rawtext | 1529 # _cache only stores rawtext |
1530 if raw: | 1530 if raw: |
1531 return self._cache[2] | 1531 return self._revisioncache[2] |
1532 # duplicated, but good for perf | 1532 # duplicated, but good for perf |
1533 if rev is None: | 1533 if rev is None: |
1534 rev = self.rev(node) | 1534 rev = self.rev(node) |
1535 if flags is None: | 1535 if flags is None: |
1536 flags = self.flags(rev) | 1536 flags = self.flags(rev) |
1537 # no extra flags set, no flag processor runs, text = rawtext | 1537 # no extra flags set, no flag processor runs, text = rawtext |
1538 if flags == REVIDX_DEFAULT_FLAGS: | 1538 if flags == REVIDX_DEFAULT_FLAGS: |
1539 return self._cache[2] | 1539 return self._revisioncache[2] |
1540 # rawtext is reusable. need to run flag processor | 1540 # rawtext is reusable. need to run flag processor |
1541 rawtext = self._cache[2] | 1541 rawtext = self._revisioncache[2] |
1542 | 1542 |
1543 cachedrev = self._cache[1] | 1543 cachedrev = self._revisioncache[1] |
1544 | 1544 |
1545 # look up what we need to read | 1545 # look up what we need to read |
1546 if rawtext is None: | 1546 if rawtext is None: |
1547 if rev is None: | 1547 if rev is None: |
1548 rev = self.rev(node) | 1548 rev = self.rev(node) |
1549 | 1549 |
1550 chain, stopped = self._deltachain(rev, stoprev=cachedrev) | 1550 chain, stopped = self._deltachain(rev, stoprev=cachedrev) |
1551 if stopped: | 1551 if stopped: |
1552 rawtext = self._cache[2] | 1552 rawtext = self._revisioncache[2] |
1553 | 1553 |
1554 # drop cache to save memory | 1554 # drop cache to save memory |
1555 self._cache = None | 1555 self._revisioncache = None |
1556 | 1556 |
1557 targetsize = None | 1557 targetsize = None |
1558 rawsize = self.index[rev][2] | 1558 rawsize = self.index[rev][2] |
1559 if 0 <= rawsize: | 1559 if 0 <= rawsize: |
1560 targetsize = 4 * rawsize | 1560 targetsize = 4 * rawsize |
1563 if rawtext is None: | 1563 if rawtext is None: |
1564 rawtext = bytes(bins[0]) | 1564 rawtext = bytes(bins[0]) |
1565 bins = bins[1:] | 1565 bins = bins[1:] |
1566 | 1566 |
1567 rawtext = mdiff.patches(rawtext, bins) | 1567 rawtext = mdiff.patches(rawtext, bins) |
1568 self._cache = (node, rev, rawtext) | 1568 self._revisioncache = (node, rev, rawtext) |
1569 | 1569 |
1570 if flags is None: | 1570 if flags is None: |
1571 if rev is None: | 1571 if rev is None: |
1572 rev = self.rev(node) | 1572 rev = self.rev(node) |
1573 flags = self.flags(rev) | 1573 flags = self.flags(rev) |
1924 | 1924 |
1925 if alwayscache and rawtext is None: | 1925 if alwayscache and rawtext is None: |
1926 rawtext = deltacomputer.buildtext(revinfo, fh) | 1926 rawtext = deltacomputer.buildtext(revinfo, fh) |
1927 | 1927 |
1928 if type(rawtext) == bytes: # only accept immutable objects | 1928 if type(rawtext) == bytes: # only accept immutable objects |
1929 self._cache = (node, curr, rawtext) | 1929 self._revisioncache = (node, curr, rawtext) |
1930 self._chainbasecache[curr] = deltainfo.chainbase | 1930 self._chainbasecache[curr] = deltainfo.chainbase |
1931 return node | 1931 return node |
1932 | 1932 |
1933 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset): | 1933 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset): |
1934 # Files opened in a+ mode have inconsistent behavior on various | 1934 # Files opened in a+ mode have inconsistent behavior on various |
2130 end += rev * self._io.size | 2130 end += rev * self._io.size |
2131 | 2131 |
2132 transaction.add(self.indexfile, end) | 2132 transaction.add(self.indexfile, end) |
2133 | 2133 |
2134 # then reset internal state in memory to forget those revisions | 2134 # then reset internal state in memory to forget those revisions |
2135 self._cache = None | 2135 self._revisioncache = None |
2136 self._chaininfocache = {} | 2136 self._chaininfocache = {} |
2137 self._chunkclear() | 2137 self._chunkclear() |
2138 for x in pycompat.xrange(rev, len(self)): | 2138 for x in pycompat.xrange(rev, len(self)): |
2139 del self.nodemap[self.node(x)] | 2139 del self.nodemap[self.node(x)] |
2140 | 2140 |