histedit: factored out diff/patch logic
This patch is the first step towards a refactoring of the histedit
extension to use underlying graft machinery instead of diff/patch as
discussed in
issue3527. Replacing diff/patch with graft is necessary
to fix, for example,
issue3582.