Merge early part of branch 'jc/diff-apply-patch'