This new function mirror the python code. This first implementation does a lot
of data copies and is therefore quite slow. However my goal here is to create a
simple "frame" from where to start adding optimization.
This patch focus on the hg-core part of this work. Coming patches will do the
necessary hg-cpython work to be able to use this from Python.