Mercurial > hg
comparison mercurial/dirstate.py @ 42452:a3a8887e4426
rust: using policy.importrust from Python callers
This commit converts all current Python callers of
mercurial.rustext to the new policy.importrust system.
After this point, going through policy.importrust
or policy.importmod (in some more distant future)
is mandatory for callers of Rust code outside of
Python tests.
We felt it to be appropriate to keep Rust-specific tests
run inconditionally if the Rust extensions are present.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Thu, 30 May 2019 09:14:41 +0200 |
parents | 448486e12c13 |
children | 87a34c767384 |
comparison
equal
deleted
inserted
replaced
42451:810f66b468cd | 42452:a3a8887e4426 |
---|---|
25 scmutil, | 25 scmutil, |
26 txnutil, | 26 txnutil, |
27 util, | 27 util, |
28 ) | 28 ) |
29 | 29 |
30 try: | |
31 from . import rustext | |
32 rustext.__name__ # force actual import (see hgdemandimport) | |
33 except ImportError: | |
34 rustext = None | |
35 | |
36 parsers = policy.importmod(r'parsers') | 30 parsers = policy.importmod(r'parsers') |
31 dirstatemod = policy.importrust(r'dirstate', default=parsers) | |
37 | 32 |
38 propertycache = util.propertycache | 33 propertycache = util.propertycache |
39 filecache = scmutil.filecache | 34 filecache = scmutil.filecache |
40 _rangemask = 0x7fffffff | 35 _rangemask = 0x7fffffff |
41 | 36 |
1466 # Depending on when in the process's lifetime the dirstate is parsed, | 1461 # Depending on when in the process's lifetime the dirstate is parsed, |
1467 # this can get very expensive. As a workaround, disable GC while | 1462 # this can get very expensive. As a workaround, disable GC while |
1468 # parsing the dirstate. | 1463 # parsing the dirstate. |
1469 # | 1464 # |
1470 # (we cannot decorate the function directly since it is in a C module) | 1465 # (we cannot decorate the function directly since it is in a C module) |
1471 if rustext is not None: | 1466 parse_dirstate = util.nogc(dirstatemod.parse_dirstate) |
1472 parse_dirstate = rustext.dirstate.parse_dirstate | |
1473 else: | |
1474 parse_dirstate = parsers.parse_dirstate | |
1475 | |
1476 parse_dirstate = util.nogc(parse_dirstate) | |
1477 p = parse_dirstate(self._map, self.copymap, st) | 1467 p = parse_dirstate(self._map, self.copymap, st) |
1478 if not self._dirtyparents: | 1468 if not self._dirtyparents: |
1479 self.setparents(*p) | 1469 self.setparents(*p) |
1480 | 1470 |
1481 # Avoid excess attribute lookups by fast pathing certain checks | 1471 # Avoid excess attribute lookups by fast pathing certain checks |
1482 self.__contains__ = self._map.__contains__ | 1472 self.__contains__ = self._map.__contains__ |
1483 self.__getitem__ = self._map.__getitem__ | 1473 self.__getitem__ = self._map.__getitem__ |
1484 self.get = self._map.get | 1474 self.get = self._map.get |
1485 | 1475 |
1486 def write(self, st, now): | 1476 def write(self, st, now): |
1487 if rustext is not None: | 1477 st.write(dirstatemod.pack_dirstate(self._map, self.copymap, |
1488 pack_dirstate = rustext.dirstate.pack_dirstate | 1478 self.parents(), now)) |
1489 else: | |
1490 pack_dirstate = parsers.pack_dirstate | |
1491 | |
1492 st.write(pack_dirstate(self._map, self.copymap, | |
1493 self.parents(), now)) | |
1494 st.close() | 1479 st.close() |
1495 self._dirtyparents = False | 1480 self._dirtyparents = False |
1496 self.nonnormalset, self.otherparentset = self.nonnormalentries() | 1481 self.nonnormalset, self.otherparentset = self.nonnormalentries() |
1497 | 1482 |
1498 @propertycache | 1483 @propertycache |