Refactor out common diff generation code

The post and diff commands were using seperate repeated code for
generating diffs. This common code is now a function which the
commands can call to generate the diff.

Reviewed at http://reviews.reviewboard.org/r/3864/