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 |
|
|
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 |
|
|
275 | filteredrevs = self.filteredrevs | |
269 |
|
|
276 | if safehasattr(revs, 'first'): # smartset | |
270 |
|
|
277 | offenders = revs & filteredrevs | |
271 |
|
|
278 | else: | |
272 |
|
|
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 |
|
|
303 | def rev(self, node): | |
297 |
|
|
304 | """filtered version of revlog.rev""" | |
298 |
|
|
305 | r = super(filteredchangelogmixin, self).rev(node) | |
299 |
|
|
306 | if r in self.filteredrevs: | |
300 |
|
|
307 | raise error.FilteredLookupError( | |
301 |
|
|
308 | hex(node), self.indexfile, _(b'filtered node') | |
302 |
|
|
309 | ) | |
303 |
|
|
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 |
|
|
312 | def node(self, rev): | |
312 |
|
|
313 | """filtered version of revlog.node""" | |
313 |
|
|
314 | if rev in self.filteredrevs: | |
314 |
|
|
315 | raise error.FilteredIndexError(rev) | |
315 |
|
|
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 |
|
|
324 | def parentrevs(self, rev): | |
318 |
|
|
325 | """filtered version of revlog.parentrevs""" | |
319 |
|
|
326 | if rev in self.filteredrevs: | |
320 |
|
|
327 | raise error.FilteredIndexError(rev) | |
321 |
|
|
328 | return super(filteredchangelogmixin, self).parentrevs(rev) | |
322 |
|
329 | |||
323 |
|
|
330 | def flags(self, rev): | |
324 |
|
|
331 | """filtered version of revlog.flags""" | |
325 |
|
|
332 | if rev in self.filteredrevs: | |
326 |
|
|
333 | raise error.FilteredIndexError(rev) | |
327 |
|
|
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