phase: apply publishing enforcement for "serve" source

When a changegroup is added by a push on a publishing server, we ensure they
are added as public. This is used to enforce publishing on server when the
client is not aware of phases. It also prevents race conditions where a reader
could see the changesets as draft before they get turned public by the client.
Finally, this save rounds trip as the client does not need additional request to
turn them public.

However, this logic was only enforced when the changegroup was from a "push"
source. And "push" is used for local pushes only. Wireprotocol push uses "serve"
as source since Mercurial 1.9. We now enforce this logic for both "push" and
"serve" sources.

One could note that this logic was mainly useful during wireprotocol exchanges.
So this code is finally put into good use, 9 versions after its introduction.
unbundle: extract checkheads in its own function

We are going to refactor the unbundle function to have it working on
a local repository too. Having this function extracted will ease the process.

In the case of non-matching heads, the function now directly raises an
exception. The top level of the function is catching it.

--HG--
extra : amend_source : e8b1ba3891b29491103174668680aea9d2b0e3b3
unbundle: extract the core logic in another function

The `exchange` module now contains an `unbundle` function that holds the core
unbundle logic. The wire protocol keeps its own unbundle function. It enforces
wireprotocol-specific logic and then calls the extracted function.

This aims at implementing unbundle for localrepo.

--HG--
extra : rebase_source : 7ad60fe5be086e1fa8d2306bd44fab77014dc255
localrepo: add unbundle support

Localrepo now supports the unbundle method of pushing changegroups. We
plan to use the unbundle call for bundle2 so it is important that all
peers supports it. The `peer.unbundle` and `peer.addchangegroup` code
path have small difference so cause some test output changes. None of those
changes seems problematic.

--HG--
extra : rebase_source : b339cceaa7413fe3d3269afe562a48c8d7558fa9
subrepo: check return code for git push (issue4223)

--HG--
extra : rebase_source : 216fcd2a8e9efccce255b3db191962c90e0ebb7a
extra : amend_source : 0fcb7394d467331ba655bc0657c258ef1c6829c8
exchange: drop useless line break

--HG--
extra : rebase_source : b9faac6e9c16213b8d435b66a6d68c077da2540f
diff: use second filename for --stat reporting on git patches (issue4221)

--HG--
extra : rebase_source : e8a5a85e81cd521e1e3551ccf951cd16d10797dd