setdiscovery: extract sample limitation in a `_limitsample` function

We need to reuse this logic for the initial query. We extract it in a function
to unsure sample limiting is applied consistently in all cases.

--HG--
branch : stable
setdiscovery: limit the size of the initial sample (issue4411)

The set discovery start by sending a "known" command with all local heads. When
the number of local heads is massive (eg: using hidden changesets) such request
becomes too large. This lead to 414 error over http, aborting the whole
process.

We limit the size of the sample used by the first query to fix this.

The test are impacted because they do test massive number of heads. But they do
not test it over real world http setup.

--HG--
branch : stable
status: make 'hg status --rev' faster when there are deleted files

In order not to avoid listing files as both added and deleted, for
example, we check for every file in the manifest if it is in the
_list_ of deleted files. This can get quite slow when there are many
deleted files. Change it to a set to make the containment check
faster. On a somewhat contrived example of the Mozilla repo with the
entire testing/ directory deleted (~14k files), this makes
'hg status --rev .^' go from 26s to 2s.

--HG--
branch : stable
extra : rebase_source : 221543f4a2362dc6d2499ffb65da53bce3193d3e
httppeer: close the temporary bundle file after two-way streaming it

This fixes several push tests in test-bundle2-exchange.t that were failing on
Windows with messages like the following:

   $ hg -R main push http://localhost:$HGPORT2/ -r 32af7686d403 \
        --bookmark book_32af
   pushing to http://localhost:$HGPORT2/
   searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   updating bookmark book_32af
   abort: The process cannot access the file because it is being used by another
            process: 'C:\path\to\tmp\bundle.hg'
   [255]

--HG--
branch : stable
extra : rebase_source : 2a440d8462a9bf9ef9d5fefb8710d9f118388477
parsers: introduce headrevsfiltered in C extension

All extensions that have this function do support filtering. The existing
headrevs function may support filtering but we cannot reliably detect whether
it does.

--HG--
branch : stable
extra : rebase_source : 1e610e38ed85ce8a8f1d649a105b838a320b88e2
changelog: use headrevsfiltered

2b5940f64750 introduced use of the new filtering headrevs C implementation. It
caught TypeError to detect when to fall back to the implementation that was
compatible with old extensions. That method was however not reliable.

Instead, use the new headrevsfiltered function when passing a filter. It will
reliably fail with AttributeError when an old extension that predates
headrevsfiltered is used.

--HG--
branch : stable
extra : rebase_source : 555d9f38051c9f69e4348e09f989fbf8160fc9a5