Patchwork D7862: dirstate: move rust fast-path calling code to its own method

login
register
mail settings
Submitter phabricator
Date Jan. 14, 2020, 5:33 p.m.
Message ID <differential-rev-PHID-DREV-4inni6bawl57rncjigag-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44328/
State Superseded
Headers show

Comments

phabricator - Jan. 14, 2020, 5:33 p.m.
Alphare created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This logic is about to get bigger, this will make it easier to read and not
  pollute the main Python logic.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7862

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 14, 2020, 5:38 p.m.
Alphare added a comment.


  Note to reviewers: this stack is part of the larger series of getting a full Rust `dirstate.status` which is most of the performance hit in bare `hg status`. More patches are coming, but I figured I would send the patches as I go to help with review timing.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7862/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7862

To: Alphare, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 15, 2020, 1:11 p.m.
pulkit added a comment.


  Absorbing the following diff to make `test-check-format.t` happy:
  
    diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
    --- a/mercurial/dirstate.py
    +++ b/mercurial/dirstate.py
    @@ -1089,9 +1089,7 @@ class dirstate(object):
             # how to read the config file.
             numcpus = self._ui.configint(b"worker", b"numcpus")
             if numcpus is not None:
    -            encoding.environ.setdefault(
    -                b'RAYON_NUM_THREADS', b'%d' % numcpus
    -            )
    +            encoding.environ.setdefault(b'RAYON_NUM_THREADS', b'%d' % numcpus)
     
             workers_enabled = self._ui.configbool(b"worker", b"enabled", True)
             if not workers_enabled:

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7862/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7862

To: Alphare, #hg-reviewers, pulkit
Cc: mercurial-devel
phabricator - Jan. 15, 2020, 2:03 p.m.
Alphare added a comment.


  In D7862#115784 <https://phab.mercurial-scm.org/D7862#115784>, @pulkit wrote:
  
  > Absorbing the following diff to make `test-check-format.t` happy:
  
  Sorry about that.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7862/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7862

To: Alphare, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1083,6 +1083,48 @@ 
                     results[next(iv)] = st
         return results
 
+    def _rust_status(self, matcher, list_clean):
+        # Force Rayon (Rust parallelism library) to respect the number of
+        # workers. This is a temporary workaround until Rust code knows
+        # how to read the config file.
+        numcpus = self._ui.configint(b"worker", b"numcpus")
+        if numcpus is not None:
+            encoding.environ.setdefault(
+                b'RAYON_NUM_THREADS', b'%d' % numcpus
+            )
+
+        workers_enabled = self._ui.configbool(b"worker", b"enabled", True)
+        if not workers_enabled:
+            encoding.environ[b"RAYON_NUM_THREADS"] = b"1"
+
+        (
+            lookup,
+            modified,
+            added,
+            removed,
+            deleted,
+            unknown,
+            clean,
+        ) = rustmod.status(
+            self._map._rustmap,
+            matcher,
+            self._rootdir,
+            bool(list_clean),
+            self._lastnormaltime,
+            self._checkexec,
+        )
+
+        status = scmutil.status(
+            modified=modified,
+            added=added,
+            removed=removed,
+            deleted=deleted,
+            unknown=unknown,
+            ignored=[],
+            clean=clean,
+        )
+        return (lookup, status)
+
     def status(self, match, subrepos, ignored, clean, unknown):
         '''Determine the status of the working copy relative to the
         dirstate and return a pair of (unsure, status), where status is of type
@@ -1127,46 +1169,7 @@ 
             use_rust = False
 
         if use_rust:
-            # Force Rayon (Rust parallelism library) to respect the number of
-            # workers. This is a temporary workaround until Rust code knows
-            # how to read the config file.
-            numcpus = self._ui.configint(b"worker", b"numcpus")
-            if numcpus is not None:
-                encoding.environ.setdefault(
-                    b'RAYON_NUM_THREADS', b'%d' % numcpus
-                )
-
-            workers_enabled = self._ui.configbool(b"worker", b"enabled", True)
-            if not workers_enabled:
-                encoding.environ[b"RAYON_NUM_THREADS"] = b"1"
-
-            (
-                lookup,
-                modified,
-                added,
-                removed,
-                deleted,
-                unknown,
-                clean,
-            ) = rustmod.status(
-                dmap._rustmap,
-                match,
-                self._rootdir,
-                bool(listclean),
-                self._lastnormaltime,
-                self._checkexec,
-            )
-
-            status = scmutil.status(
-                modified=modified,
-                added=added,
-                removed=removed,
-                deleted=deleted,
-                unknown=unknown,
-                ignored=ignored,
-                clean=clean,
-            )
-            return (lookup, status)
+            return self._rust_status(match, listclean)
 
         def noop(f):
             pass