diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -70,6 +70,7 @@ from __future__ import absolute_import import errno +import hashlib import struct from .i18n import _ @@ -461,7 +462,7 @@ return _unpack('>B', data[0:1])[0] @util.nogc -def _readmarkers(data, off=None, stop=None): +def _readmarkers(data, off=None, stop=None, filterfunc=None): """Read and enumerate markers from raw data""" diskversion = _readmarkerversion(data) if not off: @@ -471,7 +472,10 @@ if diskversion not in formats: msg = _('parsing obsolete marker: unknown version %r') % diskversion raise error.UnknownVersion(msg, version=diskversion) - return diskversion, formats[diskversion][0](data, off, stop) + markers = formats[diskversion][0](data, off, stop) + if filterfunc: + markers = filterfunc(markers) + return diskversion, markers def encodeheader(version=_fm0version): return _pack('>B', version) @@ -515,6 +519,19 @@ raise error.Abort(_('bad obsolescence marker detected: ' 'invalid successors nullid')) +def _filtermarkers(data): + """ + Return a generator that will filter markers based on the data param passed. + data: a newline-separated list of obsmarker repr hashes + """ + filterset = set(filter(lambda x: x != '', data.split('\n'))) + def filtermarkers(markers): + for marker in markers: + markerhash = hashlib.md5(marker.__repr__()).hexdigest() + if markerhash not in filterset: + yield marker + return filtermarkers + class obsstore(object): """Store obsolete markers @@ -676,7 +693,8 @@ data = self._data if not data: return [] - self._version, markers = _readmarkers(data) + filterfunc = _filtermarkers(self.svfs.tryread('obsfilter')) + self._version, markers = _readmarkers(data, filterfunc=filterfunc) markers = list(markers) _checkinvalidmarkers(markers) return markers