histedit: factor most commit creation in a function

Later commits add two important items to histedit:
- Obsolescence cycle prevention
- Proper phase conservation

Those logics must be applied to all simple operations (pick, edit, mess) and
will require verbose code.

So we introduce a new function that will provide an entry point for this new.
logic.

The function build a closure to have a clear distinction between commit
arguments and data provided to the function to fulfil its logic.

--HG--
extra : rebase_source : fff7b1b2bff9b0636a2a612f528550d9c435fb5a
histedit: record histedit source (issue3681)

Have histedit record the hex of the original changeset as already done by:
- graft
- commit --amend
- rebase

My main motivation for adding this is to prevent the creation of obsolescence cycle
(see issue3681).

Note that commit created during edit are not affected yet.

--HG--
extra : rebase_source : b206fc750ef0871d9b96987fcf6ee26068e68d96
test-histedit: fix instability creation test

The current test does not rewrite anything and therefor does not create any
instability.

We also clean up the repo state after the test. This required the rebase
extension.

--HG--
extra : rebase_source : 4d850e3d71d71ebe2527211605e479d93f885d13
test-histedit: reorder phases test and prepare for more

We are going to add a lot regarding phase of test while fixing issue3724.

This movement allows to put them after this first phase test.

--HG--
extra : rebase_source : dcc3bcf57465d5c19af65d4ac4575897fcb2a949
histedit: proper phase conservation (issue3724)

Before this changeset, histedit created all new changesets according
phases.new-commit option without any regards for the phases of the original
changesets.

This changeset fix that using the phase of rewritten changeset to decide the
phase of the resulting changeset. In case of reordering or folding, we keep
secret item secret as it seems the safer path.

temporary commit creation are not affected. They are head only and stripped at
the end of the histedit.

As for the resolution of issue3681 (obsolescence cycle prevention), we do not
handle changesets created by edit command.

--HG--
extra : rebase_source : 3f32c56abf9e0c4482a48f02e3cdcc074178bccf
hg: replace DirCleanup class with normal try/finally use