# HG changeset patch # User Pierre-Yves David # Date 1654901951 -7200 # Node ID 5b7a10ddb42f4a73dddbbc8eb3c6c41cdd8dc373 # Parent a87443d4aec026b1d9cecdf50e3289da6112e631 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. diff -r a87443d4aec0 -r 5b7a10ddb42f hgext/sparse.py --- 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', diff -r a87443d4aec0 -r 5b7a10ddb42f mercurial/dirstate.py --- 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