Show More
@@ -65,6 +65,7 b' from . import (' | |||||
65 | mdiff, |
|
65 | mdiff, | |
66 | policy, |
|
66 | policy, | |
67 | pycompat, |
|
67 | pycompat, | |
|
68 | revlogutils, | |||
68 | templatefilters, |
|
69 | templatefilters, | |
69 | util, |
|
70 | util, | |
70 | ) |
|
71 | ) | |
@@ -217,7 +218,7 b' class revlogoldio(object):' | |||||
217 | def parseindex(self, data, inline): |
|
218 | def parseindex(self, data, inline): | |
218 | s = self.size |
|
219 | s = self.size | |
219 | index = [] |
|
220 | index = [] | |
220 | nodemap = {nullid: nullrev} |
|
221 | nodemap = revlogutils.NodeMap({nullid: nullrev}) | |
221 | n = off = 0 |
|
222 | n = off = 0 | |
222 | l = len(data) |
|
223 | l = len(data) | |
223 | while off + s <= l: |
|
224 | while off + s <= l: | |
@@ -375,7 +376,7 b' class revlog(object):' | |||||
375 | # Mapping of partial identifiers to full nodes. |
|
376 | # Mapping of partial identifiers to full nodes. | |
376 | self._pcache = {} |
|
377 | self._pcache = {} | |
377 | # Mapping of revision integer to full node. |
|
378 | # Mapping of revision integer to full node. | |
378 | self._nodecache = {nullid: nullrev} |
|
379 | self._nodecache = revlogutils.NodeMap({nullid: nullrev}) | |
379 | self._nodepos = None |
|
380 | self._nodepos = None | |
380 | self._compengine = b'zlib' |
|
381 | self._compengine = b'zlib' | |
381 | self._compengineopts = {} |
|
382 | self._compengineopts = {} | |
@@ -652,7 +653,7 b' class revlog(object):' | |||||
652 | # object. |
|
653 | # object. | |
653 | self._nodecache.clearcaches() |
|
654 | self._nodecache.clearcaches() | |
654 | except AttributeError: |
|
655 | except AttributeError: | |
655 | self._nodecache = {nullid: nullrev} |
|
656 | self._nodecache = revlogutils.NodeMap({nullid: nullrev}) | |
656 | self._nodepos = None |
|
657 | self._nodepos = None | |
657 |
|
658 | |||
658 | def rev(self, node): |
|
659 | def rev(self, node): | |
@@ -661,28 +662,29 b' class revlog(object):' | |||||
661 | except TypeError: |
|
662 | except TypeError: | |
662 | raise |
|
663 | raise | |
663 | except error.RevlogError: |
|
664 | except error.RevlogError: | |
664 | # parsers.c radix tree lookup failed |
|
665 | if not isinstance(self._nodecache, revlogutils.NodeMap): | |
665 | if node == wdirid or node in wdirfilenodeids: |
|
666 | # parsers.c radix tree lookup failed | |
666 | raise error.WdirUnsupported |
|
667 | if node == wdirid or node in wdirfilenodeids: | |
667 | raise error.LookupError(node, self.indexfile, _(b'no node')) |
|
668 | raise error.WdirUnsupported | |
668 | except KeyError: |
|
669 | raise error.LookupError(node, self.indexfile, _(b'no node')) | |
669 | # pure python cache lookup failed |
|
|||
670 | n = self._nodecache |
|
|||
671 | i = self.index |
|
|||
672 | p = self._nodepos |
|
|||
673 | if p is None: |
|
|||
674 | p = len(i) - 1 |
|
|||
675 | else: |
|
670 | else: | |
676 | assert p < len(i) |
|
671 | # pure python cache lookup failed | |
677 | for r in pycompat.xrange(p, -1, -1): |
|
672 | n = self._nodecache | |
678 |
|
|
673 | i = self.index | |
679 |
|
|
674 | p = self._nodepos | |
680 |
if |
|
675 | if p is None: | |
681 |
|
|
676 | p = len(i) - 1 | |
682 |
|
|
677 | else: | |
683 | if node == wdirid or node in wdirfilenodeids: |
|
678 | assert p < len(i) | |
684 | raise error.WdirUnsupported |
|
679 | for r in pycompat.xrange(p, -1, -1): | |
685 | raise error.LookupError(node, self.indexfile, _(b'no node')) |
|
680 | v = i[r][7] | |
|
681 | n[v] = r | |||
|
682 | if v == node: | |||
|
683 | self._nodepos = r - 1 | |||
|
684 | return r | |||
|
685 | if node == wdirid or node in wdirfilenodeids: | |||
|
686 | raise error.WdirUnsupported | |||
|
687 | raise error.LookupError(node, self.indexfile, _(b'no node')) | |||
686 |
|
688 | |||
687 | # Accessors for index entries. |
|
689 | # Accessors for index entries. | |
688 |
|
690 |
@@ -0,0 +1,14 b'' | |||||
|
1 | # mercurial.revlogutils -- basic utilities for revlog | |||
|
2 | # | |||
|
3 | # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net> | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms of the | |||
|
6 | # GNU General Public License version 2 or any later version. | |||
|
7 | ||||
|
8 | from __future__ import absolute_import | |||
|
9 | from .. import error | |||
|
10 | ||||
|
11 | ||||
|
12 | class NodeMap(dict): | |||
|
13 | def __missing__(self, x): | |||
|
14 | raise error.RevlogError('unknown node: %s' % x) |
General Comments 0
You need to be logged in to leave comments.
Login now