sparse: directly inline the `rebuild` wrapping
Core is already aware of sparse, so lets move the handful of line of code that
deal with it in `dirstate.rebuild` for the sake of simplicity.
--- a/hgext/sparse.py Sat Jun 11 00:58:41 2022 +0200
+++ b/hgext/sparse.py Sat Jun 11 00:59:11 2022 +0200
@@ -212,24 +212,6 @@
and to prevent modifications to files outside the checkout.
"""
- # dirstate.rebuild should not add non-matching files
- def _rebuild(orig, self, parent, allfiles, changedfiles=None):
- matcher = self._sparsematcher
- if matcher is not None and not matcher.always():
- allfiles = [f for f in allfiles if matcher(f)]
- if changedfiles:
- changedfiles = [f for f in changedfiles if matcher(f)]
-
- if changedfiles is not None:
- # In _rebuild, these files will be deleted from the dirstate
- # when they are not found to be in allfiles
- dirstatefilestoremove = {f for f in self if not matcher(f)}
- changedfiles = dirstatefilestoremove.union(changedfiles)
-
- return orig(self, parent, allfiles, changedfiles)
-
- extensions.wrapfunction(dirstate.dirstate, b'rebuild', _rebuild)
-
# Prevent adding files that are outside the sparse checkout
editfuncs = [
b'set_tracked',
--- a/mercurial/dirstate.py Sat Jun 11 00:58:41 2022 +0200
+++ b/mercurial/dirstate.py Sat Jun 11 00:59:11 2022 +0200
@@ -670,6 +670,20 @@
self._dirty = True
def rebuild(self, parent, allfiles, changedfiles=None):
+
+ matcher = self._sparsematcher
+ if matcher is not None and not matcher.always():
+ # should not add non-matching files
+ allfiles = [f for f in allfiles if matcher(f)]
+ if changedfiles:
+ changedfiles = [f for f in changedfiles if matcher(f)]
+
+ if changedfiles is not None:
+ # these files will be deleted from the dirstate when they are
+ # not found to be in allfiles
+ dirstatefilestoremove = {f for f in self if not matcher(f)}
+ changedfiles = dirstatefilestoremove.union(changedfiles)
+
if changedfiles is None:
# Rebuild entire dirstate
to_lookup = allfiles