Friday, 4 May 2007

Musings on diff -u

diff(1) and patch(1) are wonderful tools, but there might be still room for improvement. As someone who deals with a large number of patches, I find that patches that just move code around contain too much redundant information, and are thus difficult to read.

I'd like an addition to the unified diff format. Instead of showing a large chunk being deleted and added again later, it would factorize it, for example like this:


non modified text
-first line of moved text
[-... block number #1 ...-]
-last line of moved text
continuing...
+first line of moved text
[+... block number #1 ... +]
+last line of moved text
rest of the context goes here

For extra points, that should work across files. That could be first implemented as a post-processor to diff(1).

For extra extra bonus points, some clever version control system would use this for an enhanced version of the annotate/blame/praise command, so it could show history even for code that was moved around.

No comments: