##// END OF EJS Templates
revlog: deprecate direct `nodemap` access...
marmoute -
r43974:02802fa8 default
parent child Browse files
Show More
@@ -47,8 +47,14 b' def offset_type(offset, type):'
47
47
48
48
49 class BaseIndexObject(object):
49 class BaseIndexObject(object):
50 @property
51 def nodemap(self):
52 msg = "index.nodemap is deprecated, " "use index.[has_node|rev|get_rev]"
53 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
54 return self._nodemap
55
50 @util.propertycache
56 @util.propertycache
51 def nodemap(self):
57 def _nodemap(self):
52 nodemap = revlogutils.NodeMap({nullid: nullrev})
58 nodemap = revlogutils.NodeMap({nullid: nullrev})
53 for r in range(0, len(self)):
59 for r in range(0, len(self)):
54 n = self[r][7]
60 n = self[r][7]
@@ -57,35 +63,35 b' class BaseIndexObject(object):'
57
63
58 def has_node(self, node):
64 def has_node(self, node):
59 """return True if the node exist in the index"""
65 """return True if the node exist in the index"""
60 return node in self.nodemap
66 return node in self._nodemap
61
67
62 def rev(self, node):
68 def rev(self, node):
63 """return a revision for a node
69 """return a revision for a node
64
70
65 If the node is unknown, raise a RevlogError"""
71 If the node is unknown, raise a RevlogError"""
66 return self.nodemap[node]
72 return self._nodemap[node]
67
73
68 def get_rev(self, node):
74 def get_rev(self, node):
69 """return a revision for a node
75 """return a revision for a node
70
76
71 If the node is unknown, return None"""
77 If the node is unknown, return None"""
72 return self.nodemap.get(node)
78 return self._nodemap.get(node)
73
79
74 def _stripnodes(self, start):
80 def _stripnodes(self, start):
75 if 'nodemap' in vars(self):
81 if '_nodemap' in vars(self):
76 for r in range(start, len(self)):
82 for r in range(start, len(self)):
77 n = self[r][7]
83 n = self[r][7]
78 del self.nodemap[n]
84 del self._nodemap[n]
79
85
80 def clearcaches(self):
86 def clearcaches(self):
81 self.__dict__.pop('nodemap', None)
87 self.__dict__.pop('_nodemap', None)
82
88
83 def __len__(self):
89 def __len__(self):
84 return self._lgt + len(self._extra)
90 return self._lgt + len(self._extra)
85
91
86 def append(self, tup):
92 def append(self, tup):
87 if 'nodemap' in vars(self):
93 if '_nodemap' in vars(self):
88 self.nodemap[tup[7]] = len(self)
94 self._nodemap[tup[7]] = len(self)
89 self._extra.append(tup)
95 self._extra.append(tup)
90
96
91 def _check_index(self, i):
97 def _check_index(self, i):
@@ -205,8 +205,14 b' indexformatv0_unpack = indexformatv0.unp'
205
205
206
206
207 class revlogoldindex(list):
207 class revlogoldindex(list):
208 @property
209 def nodemap(self):
210 msg = "index.nodemap is deprecated, " "use index.[has_node|rev|get_rev]"
211 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
212 return self._nodemap
213
208 @util.propertycache
214 @util.propertycache
209 def nodemap(self):
215 def _nodemap(self):
210 nodemap = revlogutils.NodeMap({nullid: nullrev})
216 nodemap = revlogutils.NodeMap({nullid: nullrev})
211 for r in range(0, len(self)):
217 for r in range(0, len(self)):
212 n = self[r][7]
218 n = self[r][7]
@@ -215,33 +221,33 b' class revlogoldindex(list):'
215
221
216 def has_node(self, node):
222 def has_node(self, node):
217 """return True if the node exist in the index"""
223 """return True if the node exist in the index"""
218 return node in self.nodemap
224 return node in self._nodemap
219
225
220 def rev(self, node):
226 def rev(self, node):
221 """return a revision for a node
227 """return a revision for a node
222
228
223 If the node is unknown, raise a RevlogError"""
229 If the node is unknown, raise a RevlogError"""
224 return self.nodemap[node]
230 return self._nodemap[node]
225
231
226 def get_rev(self, node):
232 def get_rev(self, node):
227 """return a revision for a node
233 """return a revision for a node
228
234
229 If the node is unknown, return None"""
235 If the node is unknown, return None"""
230 return self.nodemap.get(node)
236 return self._nodemap.get(node)
231
237
232 def append(self, tup):
238 def append(self, tup):
233 self.nodemap[tup[7]] = len(self)
239 self._nodemap[tup[7]] = len(self)
234 super(revlogoldindex, self).append(tup)
240 super(revlogoldindex, self).append(tup)
235
241
236 def __delitem__(self, i):
242 def __delitem__(self, i):
237 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
243 if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
238 raise ValueError(b"deleting slices only supports a:-1 with step 1")
244 raise ValueError(b"deleting slices only supports a:-1 with step 1")
239 for r in pycompat.xrange(i.start, len(self)):
245 for r in pycompat.xrange(i.start, len(self)):
240 del self.nodemap[self[r][7]]
246 del self._nodemap[self[r][7]]
241 super(revlogoldindex, self).__delitem__(i)
247 super(revlogoldindex, self).__delitem__(i)
242
248
243 def clearcaches(self):
249 def clearcaches(self):
244 self.__dict__.pop('nodemap', None)
250 self.__dict__.pop('_nodemap', None)
245
251
246 def __getitem__(self, i):
252 def __getitem__(self, i):
247 if i == -1:
253 if i == -1:
@@ -579,7 +585,6 b' class revlog(object):'
579 _(b"index %s is corrupted") % self.indexfile
585 _(b"index %s is corrupted") % self.indexfile
580 )
586 )
581 self.index, self._chunkcache = d
587 self.index, self._chunkcache = d
582 self.nodemap = self.index.nodemap
583 if not self._chunkcache:
588 if not self._chunkcache:
584 self._chunkclear()
589 self._chunkclear()
585 # revnum -> (chain-length, sum-delta-length)
590 # revnum -> (chain-length, sum-delta-length)
@@ -650,8 +655,13 b' class revlog(object):'
650 """iterate over all rev in this revlog (from start to stop)"""
655 """iterate over all rev in this revlog (from start to stop)"""
651 return storageutil.iterrevs(len(self), start=start, stop=stop)
656 return storageutil.iterrevs(len(self), start=start, stop=stop)
652
657
653 @util.propertycache
658 @property
654 def nodemap(self):
659 def nodemap(self):
660 msg = (
661 "revlog.nodemap is deprecated, "
662 "use revlog.index.[has_node|rev|get_rev]"
663 )
664 util.nouideprecwarn(msg, b'5.3', stacklevel=2)
655 return self.index.nodemap
665 return self.index.nodemap
656
666
657 @property
667 @property
General Comments 0
You need to be logged in to leave comments. Login now