Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 50925:d718eddf01d9
safehasattr: drop usage in favor of hasattr
The two functions should now be equivalent at least in their usage in core.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 31 Aug 2023 23:56:15 +0200 |
parents | 4a3a9d961561 |
children | 18c8c18993f0 |
comparison
equal
deleted
inserted
replaced
50924:7a8ea1397816 | 50925:d718eddf01d9 |
---|---|
165 # True if a fast implementation for persistent-nodemap is available | 165 # True if a fast implementation for persistent-nodemap is available |
166 # | 166 # |
167 # We also consider we have a "fast" implementation in "pure" python because | 167 # We also consider we have a "fast" implementation in "pure" python because |
168 # people using pure don't really have performance consideration (and a | 168 # people using pure don't really have performance consideration (and a |
169 # wheelbarrow of other slowness source) | 169 # wheelbarrow of other slowness source) |
170 HAS_FAST_PERSISTENT_NODEMAP = rustrevlog is not None or util.safehasattr( | 170 HAS_FAST_PERSISTENT_NODEMAP = rustrevlog is not None or hasattr( |
171 parsers, 'BaseIndexObject' | 171 parsers, 'BaseIndexObject' |
172 ) | 172 ) |
173 | 173 |
174 | 174 |
175 @interfaceutil.implementer(repository.irevisiondelta) | 175 @interfaceutil.implementer(repository.irevisiondelta) |
212 # call the C implementation to parse the index data | 212 # call the C implementation to parse the index data |
213 index, cache = parsers.parse_index2(data, inline, format=CHANGELOGV2) | 213 index, cache = parsers.parse_index2(data, inline, format=CHANGELOGV2) |
214 return index, cache | 214 return index, cache |
215 | 215 |
216 | 216 |
217 if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | 217 if hasattr(parsers, 'parse_index_devel_nodemap'): |
218 | 218 |
219 def parse_index_v1_nodemap(data, inline): | 219 def parse_index_v1_nodemap(data, inline): |
220 index, cache = parsers.parse_index_devel_nodemap(data, inline) | 220 index, cache = parsers.parse_index_devel_nodemap(data, inline) |
221 return index, cache | 221 return index, cache |
222 | 222 |
728 d = self._parse_index(index_data, self._inline) | 728 d = self._parse_index(index_data, self._inline) |
729 index, chunkcache = d | 729 index, chunkcache = d |
730 use_nodemap = ( | 730 use_nodemap = ( |
731 not self._inline | 731 not self._inline |
732 and self._nodemap_file is not None | 732 and self._nodemap_file is not None |
733 and util.safehasattr(index, 'update_nodemap_data') | 733 and hasattr(index, 'update_nodemap_data') |
734 ) | 734 ) |
735 if use_nodemap: | 735 if use_nodemap: |
736 nodemap_data = nodemaputil.persisted_data(self) | 736 nodemap_data = nodemaputil.persisted_data(self) |
737 if nodemap_data is not None: | 737 if nodemap_data is not None: |
738 docket = nodemap_data[0] | 738 docket = nodemap_data[0] |
909 # The python code is the one responsible for validating the docket, we | 909 # The python code is the one responsible for validating the docket, we |
910 # end up having to refresh it here. | 910 # end up having to refresh it here. |
911 use_nodemap = ( | 911 use_nodemap = ( |
912 not self._inline | 912 not self._inline |
913 and self._nodemap_file is not None | 913 and self._nodemap_file is not None |
914 and util.safehasattr(self.index, 'update_nodemap_data') | 914 and hasattr(self.index, 'update_nodemap_data') |
915 ) | 915 ) |
916 if use_nodemap: | 916 if use_nodemap: |
917 nodemap_data = nodemaputil.persisted_data(self) | 917 nodemap_data = nodemaputil.persisted_data(self) |
918 if nodemap_data is not None: | 918 if nodemap_data is not None: |
919 self._nodemap_docket = nodemap_data[0] | 919 self._nodemap_docket = nodemap_data[0] |
1885 | 1885 |
1886 def issnapshot(self, rev): | 1886 def issnapshot(self, rev): |
1887 """tells whether rev is a snapshot""" | 1887 """tells whether rev is a snapshot""" |
1888 if not self._sparserevlog: | 1888 if not self._sparserevlog: |
1889 return self.deltaparent(rev) == nullrev | 1889 return self.deltaparent(rev) == nullrev |
1890 elif util.safehasattr(self.index, 'issnapshot'): | 1890 elif hasattr(self.index, 'issnapshot'): |
1891 # directly assign the method to cache the testing and access | 1891 # directly assign the method to cache the testing and access |
1892 self.issnapshot = self.index.issnapshot | 1892 self.issnapshot = self.index.issnapshot |
1893 return self.issnapshot(rev) | 1893 return self.issnapshot(rev) |
1894 if rev == nullrev: | 1894 if rev == nullrev: |
1895 return True | 1895 return True |