##// END OF EJS Templates
repoview: define filteredchangelog as a top-level (non-local) class...
Martin von Zweigbergk -
r43797:bad4a26b default
parent child Browse files
Show More
@@ -227,108 +227,111 b' def wrapchangelog(unfichangelog, filtere'
227 cl = copy.copy(unfichangelog)
227 cl = copy.copy(unfichangelog)
228 cl.filteredrevs = filteredrevs
228 cl.filteredrevs = filteredrevs
229
229
230 class filteredchangelog(cl.__class__):
230 cl.__class__ = type(
231 def tiprev(self):
231 'filteredchangelog', (filteredchangelogmixin, cl.__class__), {}
232 """filtered version of revlog.tiprev"""
232 )
233 for i in pycompat.xrange(len(self) - 1, -2, -1):
234 if i not in self.filteredrevs:
235 return i
236
233
237 def __contains__(self, rev):
234 return cl
238 """filtered version of revlog.__contains__"""
235
239 return 0 <= rev < len(self) and rev not in self.filteredrevs
240
236
241 def __iter__(self):
237 class filteredchangelogmixin(object):
242 """filtered version of revlog.__iter__"""
238 def tiprev(self):
239 """filtered version of revlog.tiprev"""
240 for i in pycompat.xrange(len(self) - 1, -2, -1):
241 if i not in self.filteredrevs:
242 return i
243
243
244 def filterediter():
244 def __contains__(self, rev):
245 for i in pycompat.xrange(len(self)):
245 """filtered version of revlog.__contains__"""
246 if i not in self.filteredrevs:
246 return 0 <= rev < len(self) and rev not in self.filteredrevs
247 yield i
248
247
249 return filterediter()
248 def __iter__(self):
249 """filtered version of revlog.__iter__"""
250
250
251 def revs(self, start=0, stop=None):
251 def filterediter():
252 """filtered version of revlog.revs"""
252 for i in pycompat.xrange(len(self)):
253 for i in super(filteredchangelog, self).revs(start, stop):
254 if i not in self.filteredrevs:
253 if i not in self.filteredrevs:
255 yield i
254 yield i
256
255
257 def _checknofilteredinrevs(self, revs):
256 return filterediter()
258 """raise the appropriate error if 'revs' contains a filtered revision
257
258 def revs(self, start=0, stop=None):
259 """filtered version of revlog.revs"""
260 for i in super(filteredchangelogmixin, self).revs(start, stop):
261 if i not in self.filteredrevs:
262 yield i
259
263
260 This returns a version of 'revs' to be used thereafter by the caller.
264 def _checknofilteredinrevs(self, revs):
261 In particular, if revs is an iterator, it is converted into a set.
265 """raise the appropriate error if 'revs' contains a filtered revision
262 """
266
263 safehasattr = util.safehasattr
267 This returns a version of 'revs' to be used thereafter by the caller.
264 if safehasattr(revs, '__next__'):
268 In particular, if revs is an iterator, it is converted into a set.
265 # Note that inspect.isgenerator() is not true for iterators,
269 """
266 revs = set(revs)
270 safehasattr = util.safehasattr
271 if safehasattr(revs, '__next__'):
272 # Note that inspect.isgenerator() is not true for iterators,
273 revs = set(revs)
267
274
268 filteredrevs = self.filteredrevs
275 filteredrevs = self.filteredrevs
269 if safehasattr(revs, 'first'): # smartset
276 if safehasattr(revs, 'first'): # smartset
270 offenders = revs & filteredrevs
277 offenders = revs & filteredrevs
271 else:
278 else:
272 offenders = filteredrevs.intersection(revs)
279 offenders = filteredrevs.intersection(revs)
273
274 for rev in offenders:
275 raise error.FilteredIndexError(rev)
276 return revs
277
280
278 def headrevs(self, revs=None):
281 for rev in offenders:
279 if revs is None:
282 raise error.FilteredIndexError(rev)
280 try:
283 return revs
281 return self.index.headrevsfiltered(self.filteredrevs)
282 # AttributeError covers non-c-extension environments and
283 # old c extensions without filter handling.
284 except AttributeError:
285 return self._headrevs()
286
284
287 revs = self._checknofilteredinrevs(revs)
285 def headrevs(self, revs=None):
288 return super(filteredchangelog, self).headrevs(revs)
286 if revs is None:
287 try:
288 return self.index.headrevsfiltered(self.filteredrevs)
289 # AttributeError covers non-c-extension environments and
290 # old c extensions without filter handling.
291 except AttributeError:
292 return self._headrevs()
289
293
290 def strip(self, *args, **kwargs):
294 revs = self._checknofilteredinrevs(revs)
291 # XXX make something better than assert
295 return super(filteredchangelogmixin, self).headrevs(revs)
292 # We can't expect proper strip behavior if we are filtered.
296
293 assert not self.filteredrevs
297 def strip(self, *args, **kwargs):
294 super(filteredchangelog, self).strip(*args, **kwargs)
298 # XXX make something better than assert
299 # We can't expect proper strip behavior if we are filtered.
300 assert not self.filteredrevs
301 super(filteredchangelogmixin, self).strip(*args, **kwargs)
295
302
296 def rev(self, node):
303 def rev(self, node):
297 """filtered version of revlog.rev"""
304 """filtered version of revlog.rev"""
298 r = super(filteredchangelog, self).rev(node)
305 r = super(filteredchangelogmixin, self).rev(node)
299 if r in self.filteredrevs:
306 if r in self.filteredrevs:
300 raise error.FilteredLookupError(
307 raise error.FilteredLookupError(
301 hex(node), self.indexfile, _(b'filtered node')
308 hex(node), self.indexfile, _(b'filtered node')
302 )
309 )
303 return r
310 return r
304
305 def node(self, rev):
306 """filtered version of revlog.node"""
307 if rev in self.filteredrevs:
308 raise error.FilteredIndexError(rev)
309 return super(filteredchangelog, self).node(rev)
310
311
311 def linkrev(self, rev):
312 def node(self, rev):
312 """filtered version of revlog.linkrev"""
313 """filtered version of revlog.node"""
313 if rev in self.filteredrevs:
314 if rev in self.filteredrevs:
314 raise error.FilteredIndexError(rev)
315 raise error.FilteredIndexError(rev)
315 return super(filteredchangelog, self).linkrev(rev)
316 return super(filteredchangelogmixin, self).node(rev)
317
318 def linkrev(self, rev):
319 """filtered version of revlog.linkrev"""
320 if rev in self.filteredrevs:
321 raise error.FilteredIndexError(rev)
322 return super(filteredchangelogmixin, self).linkrev(rev)
316
323
317 def parentrevs(self, rev):
324 def parentrevs(self, rev):
318 """filtered version of revlog.parentrevs"""
325 """filtered version of revlog.parentrevs"""
319 if rev in self.filteredrevs:
326 if rev in self.filteredrevs:
320 raise error.FilteredIndexError(rev)
327 raise error.FilteredIndexError(rev)
321 return super(filteredchangelog, self).parentrevs(rev)
328 return super(filteredchangelogmixin, self).parentrevs(rev)
322
329
323 def flags(self, rev):
330 def flags(self, rev):
324 """filtered version of revlog.flags"""
331 """filtered version of revlog.flags"""
325 if rev in self.filteredrevs:
332 if rev in self.filteredrevs:
326 raise error.FilteredIndexError(rev)
333 raise error.FilteredIndexError(rev)
327 return super(filteredchangelog, self).flags(rev)
334 return super(filteredchangelogmixin, self).flags(rev)
328
329 cl.__class__ = filteredchangelog
330
331 return cl
332
335
333
336
334 class repoview(object):
337 class repoview(object):
General Comments 0
You need to be logged in to leave comments. Login now