153 """ |
153 """ |
154 |
154 |
155 def __init__(self, repo, filtername): |
155 def __init__(self, repo, filtername): |
156 object.__setattr__(self, '_unfilteredrepo', repo) |
156 object.__setattr__(self, '_unfilteredrepo', repo) |
157 object.__setattr__(self, 'filtername', filtername) |
157 object.__setattr__(self, 'filtername', filtername) |
|
158 object.__setattr__(self, '_clcachekey', None) |
|
159 object.__setattr__(self, '_clcache', None) |
158 |
160 |
159 # not a cacheproperty on purpose we shall implement a proper cache later |
161 # not a cacheproperty on purpose we shall implement a proper cache later |
160 @property |
162 @property |
161 def changelog(self): |
163 def changelog(self): |
162 """return a filtered version of the changeset |
164 """return a filtered version of the changeset |
163 |
165 |
164 this changelog must not be used for writing""" |
166 this changelog must not be used for writing""" |
165 # some cache may be implemented later |
167 # some cache may be implemented later |
166 cl = copy.copy(self._unfilteredrepo.changelog) |
168 unfi = self._unfilteredrepo |
167 cl.filteredrevs = filterrevs(self._unfilteredrepo, self.filtername) |
169 unfichangelog = unfi.changelog |
|
170 revs = filterrevs(unfi, self.filtername) |
|
171 cl = self._clcache |
|
172 newkey = (len(unfichangelog), unfichangelog.tip(), hash(revs)) |
|
173 if cl is not None: |
|
174 # we need to check curkey too for some obscure reason. |
|
175 # MQ test show a corruption of the underlying repo (in _clcache) |
|
176 # without change in the cachekey. |
|
177 oldfilter = cl.filteredrevs |
|
178 try: |
|
179 cl.filterrevs = () # disable filtering for tip |
|
180 curkey = (len(cl), cl.tip(), hash(oldfilter)) |
|
181 finally: |
|
182 cl.filteredrevs = oldfilter |
|
183 if newkey != self._clcachekey or newkey != curkey: |
|
184 cl = None |
|
185 # could have been made None by the previous if |
|
186 if cl is None: |
|
187 cl = copy.copy(unfichangelog) |
|
188 cl.filteredrevs = revs |
|
189 object.__setattr__(self, '_clcache', cl) |
|
190 object.__setattr__(self, '_clcachekey', newkey) |
168 return cl |
191 return cl |
169 |
192 |
170 def unfiltered(self): |
193 def unfiltered(self): |
171 """Return an unfiltered version of a repo""" |
194 """Return an unfiltered version of a repo""" |
172 return self._unfilteredrepo |
195 return self._unfilteredrepo |