Generating “Unified Diff” Files with ClearCase
In my company, we recently migrated from CVS to ClearCase. We were a bit thrown off by the fact that ClearCase doesn’t readily provide diff files that span multiple files. We have all been used to reviewing CVS diff files which do so. People here had to come up with their own scripts to remedy this issue. Here’s what I’ve been using so far:
cleartool lsco -cvi -r -s | xargs -n1 cleartool diff -pred -ser | egrep -v "^(Files|Directories) are identical"
This Unix shell command will generate the diff output (which you can redirect to a file) recursively (-r) for all files that are checked out within the current directory, on the current view (-cvi).
The output is not exactly a unified diff file (I believe that it can’t be directly used with the patch command) but it still is a human-readable diff that spans multiple files.
The reason that I use -serial_format (-ser) and not -diff_format is that -diff_format suppresses the file headers and obviously a “unified diff” file doesn’t make sense when you don’t know where each individual file starts and ends.
January 24th, 2008 at 9:32 am
Thanks for this, it pointed me in the right direction. I was able to move all changes created in one branch over into another branch by scripting this and using diff and patch. I did it in 2 stages to keep an eye in everything.
NOTE: following scripts were run under cygwin on windows. In particular, they use pushd and popd, easily changed to work under *nix.
They assume DESTINATION variable set.
Stage 1, for each checked out file in source branch copy any non-existent files over to other branch, and check out any files that do exist:
Stage 2, for each checked out file in source branch create diff between it and file in dest branch, then patch file in dest branch (new files will have empty patches applie. NOTE: you could easily diff against current ClearCase state using cleartool diff -pred -diff as in original article)