Handle diffs with no newline at end of file

Also simplify the finalization logic.