Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dirstate.py @ 47136:9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Before this changeset, Python code first creates an empty `DirstateMap` Rust
object, then immediately calls its `read` method with a byte string of the
contents of the `.hg/dirstate` file.
This makes that byte string available to the constructor of `DirstateMap`
in the hg-cpython crate. This is a first step towards enabling parts of
`DirstateMap` in the hg-core crate to borrow from this buffer without copying.
Differential Revision: https://phab.mercurial-scm.org/D10556
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 30 Apr 2021 18:13:31 +0200 |
parents | b6339a993b91 |
children | ed0d54b20c5b |
line wrap: on
line diff
--- a/mercurial/dirstate.py Fri Apr 30 15:40:11 2021 +0200 +++ b/mercurial/dirstate.py Fri Apr 30 18:13:31 2021 +0200 @@ -1775,20 +1775,6 @@ def get(self, *args, **kwargs): return self._rustmap.get(*args, **kwargs) - @propertycache - def _rustmap(self): - """ - Fills the Dirstatemap when called. - """ - use_dirstate_tree = self._ui.configbool( - b"experimental", - b"dirstate-tree.in-memory", - False, - ) - self._rustmap = rustmod.DirstateMap(use_dirstate_tree) - self.read() - return self._rustmap - @property def copymap(self): return self._rustmap.copymap() @@ -1872,7 +1858,11 @@ return self._parents - def read(self): + @propertycache + def _rustmap(self): + """ + Fills the Dirstatemap when called. + """ # ignore HG_PENDING because identity is used only for writing self.identity = util.filestat.frompath( self._opener.join(self._filename) @@ -1887,18 +1877,24 @@ except IOError as err: if err.errno != errno.ENOENT: raise - return - if not st: - return + st = b'' - parse_dirstate = util.nogc(self._rustmap.read) - parents = parse_dirstate(st) + use_dirstate_tree = self._ui.configbool( + b"experimental", + b"dirstate-tree.in-memory", + False, + ) + self._rustmap, parents = rustmod.DirstateMap.new( + use_dirstate_tree, st + ) + if parents and not self._dirtyparents: self.setparents(*parents) self.__contains__ = self._rustmap.__contains__ self.__getitem__ = self._rustmap.__getitem__ self.get = self._rustmap.get + return self._rustmap def write(self, st, now): parents = self.parents()