Tip #3: Make Life Easier for Your Code Reviewer
By ByronNevins on Aug 08, 2011
There are probably a hundred applications that will package up code changes in various cool ways. You could also write your own -- unfortunately it's one of those cases where the time you save using the tool will never approach the time you spent making the tool.
I get code review requests fairly often and they are almost always like this:
Below are the diffs for my change. Please review
And as promised the output of some diff tool is below in the email. What if the context around the diffs isn't big enough? What if I hate the diff tool formatting? What if I want to compile and run the actual changes in my environment?
I can't do any of the above quickly and easily with the raw diffs embedded in the email. Even copying and pasting them is usually a big pain because of the prepended plus signs.
Here are my requirements for code review submitters (Please?!?)
- Send out the actual changed source files
- Make it very very easy to get those source file into the right directory. Don't make me type in commands with endlessly long paths!
- Send me the diffs as a file and have it appear directly in the email (maybe the change is easy and I don't need to waste time dealing with file attachments)
And here is the solution I use. It is simple and old-fashioned and works great:
- Create the following script (Windows version). I use this script constantly when I'm working on source code. That's why I named it "s.bat". Usually I don't use the "dome.bat" file but I always create it just in case. I sort the output to get all the modified files together.
svn status | sort | tee dome.bat
- To submit the changes to a code reviewer, I want him or her to get the diffs file, and all changed files. I collect the diffs in a file like so (make a script out of it!)
svn diff > diffs.txt
- Here is the trick. Edit the dome.bat file from step 1 above. Delete the uninteresting lines and QUICKLY edit the Modified or Added lines to do this:
jar cvfM mychanges.jar diffs.txt c:/some/gigantic/ugly/long/path/foo.java c:/some/even/uglier/gigantic/long/path/foo2.java
- Now I attach mychanges.jar to an email and also copy the diffs to the email message. I tell the reviewer which directory to change to and how to unpack the source files. E.g.
"cd to core/kernel and run jar xvf mychanges.jar to overlay my changes in your installation"
It sounds like a big deal but it shouldn't take more than a couple minutes and it makes life more pleasant for the reviewer. Note how the reviewer can do this:
jar cvfM temp.zip src
jar xvf mychanges.jar
run his or her favorite diff tools
compile and build, look at the code in a debugger or whatever
when review is complete, jar xvf temp.zip