



































































ClearCase compare with arbitrary version hack
There’s “Compare with previous version” in the ClearCase context menu. Useful. But how much more useful would it be to compare with an arbitrary version! Of course, one could always do it in the version tree, but it’s a bit time consuming, for files with a lot of versions; Entering a version extended path on the other hand, would be daunting.
Before looking at the ClearCase context menu, here are the scripts that will do the things for us.
1. Here’s one that shows a list of labels and compares with the one chosen:
@rem = ' This is a perl script for NT.
@echo off
@ccperl "%~f0" %1
@goto endofperl
@rem ';
require File::Temp;
use File::Temp qw/ :POSIX /;
# create the temp file
($fh, $file) = tmpnam();
END
{
# get rid of the temp file at the end.
close $fh;
unlink($file) or die "Couldn't unlink $file : $!";
}
# quote for spaces
$ARGV[0]='"'.$ARGV[0].'"' if ($ARGV[0]=~/\s/);
$labels=`cleartool lshist -fmt \"\%l\" $ARGV[0]`;
$labels=~s/\)\(/\,/g;
$labels=~s/(\(|\))//g;
@labellist=split /\,\s*/,$labels;
@labellist=sort @labellist;
foreach $label (@labellist)
{
$label.=",";
}
print $fh "@labellist";
if (!system("clearprompt list -outfile $file -dfile $file -prompt \"Select label to compare with\""))
{
seek($fh, 0, 0);
$chosenlabel=< $fh>;
print $file;
`cleardlg \/diffother $ARGV[0] $ARGV[0]\@\@\\$chosenlabel`;
}
__END__
:endofperl
Create a file, say, complabel.cmd and copy & paste or get it here
2. For an arbitrary version, we just need to take the version-extended path and compare it with the path without the version:
@rem = ' This is a perl script for NT.
@echo off
@ccperl "%~f0" %1
@goto endofperl
@rem ';
# quote for spaces
if ($ARGV[0]=~/\s/)
{
$ARGV[0]=~s/(.*)\@\@/\"\1\"\@\@/;
}
$ARGV[0]=~/(.*)\@\@/;
`cleardlg \/diffother $1 $ARGV[0]`;
__END__
:endofperl
Create comp.cmd and copy & paste or get it here
I haven’t played much with them, so there may be some quirks with strange characters, et al.
Now that we have perl scripts, let’s modify the context menus. Open ClearCase Context Menu Editor (Programs>Rational Software>Rational Clearcase>Context Menu Editor). We’ll create two menu choices (just enter what’s below):
1. Compare with a Label

Of course, you need to enter your own path to the complabel.cmd.
Browse into Version Tree:

This “@@” does the magic - take a path in dynamic view, add @@ and now you can browse the version tree and all labels. Someone sent this hack to CM Crossroads, I’d happily attribute him/her, can’t find it now, though…
Now, we add the entries under dynamic view file “Checked In” and “Checked Out”, and arrange them nicely

And that’s it for the Context Menu Editor, our entries should now appear in the context menu:

Warning!!! Lame!!! To finish the comparison with an arbitrary version, we will need to add a proper command to the windows context menu. Now, I don’t have time to learn how to write Windows shell extensions, to make it all nice and smooth. So I did it in a crude way - I created a shortcut to comp.cmd and added it to my SendTo:

Now, if you want to compare with an arbitrary version of a file - in the dynamic view select Browse into Version Tree, and then in the tree select “compare with me”:

And that’s all folks.

