Merge down, copy up

If you are using any SCM that allows cheap branches (like Perforce) and are following the advices from the High-level Best Practices document, you might be interested in (or already know) Laura Wingerd’s presentation Convergence vs. Divergence: Purposeful Merging with Perforce about how to converge to codelines using Merge Down, Copy Up [PDF]. I have seen it many times that a main codeline got broken because the Merge Down, Copy Up idiom was ignored.

The detailed procedure of Merge Down, Copy Up is explained on Slide 22 of the talk. Unfortunately it doesn’t work in the presence of files with expanded keywords (type text+k). All these files don’t get reverted in step 4 (p4 diff -sr | p4 -x - revert), although they differ only in keyword expansion.

There is currently no direct way using Perforce commands to work around this problem. However, the p4 diff commands to plug in a different diff tool. My solution on Windows therefore consists of two scripts, one to set up P4DIFF and call p4 diff (revert_unchanged.bat), the other as the plug in diff tool (diff_no_keywords.bat). The scripts need a couple of additional filters like diff, grep and cut. While the cygwin grep is fine, you must not use its diff and cut binaries, because these are too much unixish and have problems with the backslash path delimiters that p4 diff is handing out (or you could perhaps use the cygwin variant of p4, if you have a current one). I have used the binaries from http://unxutils.sourceforge.net/.

Both scripts are available from the Perforce Public Depot: revert_unchanged.bat, diff_no_keywords.bat. You use them as additional step 4a after the p4 diff -sr step.

This entry was posted in Hug-Witschi, Programming. Bookmark the permalink.

Comments are closed.