51

I'd like to use my own diff when working in a clearcase snapshot view.

As far as I can see, there is no way to specify a diff tool when running "cleartool diff", so I was thinking I could run something like "mydiff <predecessor file> <modified file in my view>", but I don't know enough about ClearCase to be able to find the "predecessor file" to diff against.

Any way to do this?

Forgot to mention (until now, after reading the first two responses dealing with windows) that this is on Unix, and I am not allowed to muck with the ClearCase configuration.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
chacmool
  • 1,357
  • 2
  • 16
  • 21
  • Just added a warning about the script only running properly in *dynamic* view, in response to your comment – VonC Dec 17 '08 at 21:49

11 Answers11

61

How to change default diff tools

You can specify an external diff tool by modifying the file map, in "c:\program files\rational\ClearCase\lib\mgrs"

The WinMerge suggested by Paul actually modifies that file.

Each map line has 3 parts: the CC filetype, the CC action, and the application.

Find the section in the map file for text_file_delta file types. There you will find lines for CC actions compare, xcompare, merge, and xmerge which look like this:

text_file_delta   compare          ..\..\bin\cleardiff.exe
text_file_delta   xcompare         ..\..\bin\cleardiffmrg.exe
text_file_delta   merge            ..\..\bin\cleardiff.exe
text_file_delta   xmerge           ..\..\bin\cleardiffmrg.exe

You can replace them by the executable of your diff tool choice.


Or, a simple diff script

If you want to go full command-line on this (which I like ;-) ), a little ccperl can help:

#!/bin/perl
my ($file, $switches) = @ARGV;
$switches ||= '-ubBw';

my ($element, $version, $pred) 
    = split(/;/,`cleartool describe -fmt '%En;%Vn;%PVn' $file`);

unless ($pred) { die "ctdiff: $file has no predecessor\n"; }

exec "mydiff $switches $element\@\@$pred $file";

Warning: extended pathname (@@\...) is only accessible in dynamic view (M:\..., not snapshot view (c:\...).

The script has nothing to do with the mapfile presented above:

  • that file defines 'Type Merge Managers'.
  • This script allows you to run any merge manager on any file you want, without reading any map file to look for the right diff exe to use for a given file.

Here, you provide to the script both informations: the file (as a parameter) and the diff exe to run (within the script implementation: replace mydiff by whatever diff exe you want).


Or, improved diff script (works in static/snapshot views too)

Here is a version of this script which works for both snapshot and dynamic view.

For snapshot view, I use the chacmool's suggestion: cleartool get.

Again, you can replace the diff command included in this script by the tool of your choosing.

#!/bin/perl
my ($file, $switches) = @ARGV;
$switches ||= '-u';

my ($element, $version, $pred) 
    = split(/;/,`cleartool describe -fmt '%En;%Vn;%PVn' $file`);

unless ($pred) { die "ctdiff: $file has no predecessor\n"; }

# figure out if view is dynamic or snapshot
my $str1 = `cleartool lsview -long -cview`;
if($? == 0) { dodie("pred.pl must be executed within a clearcase view"); }
my @ary1 = grep(/Global path:/, split(/\n/, $str1));
if($str1 =~ /View attributes: snapshot/sm) { $is_snapshot = 1; }

my $predfile = "$element\@\@$pred";
$predfile =~ s/\'//g;#'
#printf("$predfile\n");
if ($is_snapshot) { 
  my $predtemp = "c:\\temp\\pred.txt";
  unlink($predtemp);
  my $cmd = "cleartool get -to $predtemp $predfile"; printf("$cmd\n");
  my $str2 = `$cmd`;
  $predfile = $predtemp;
}
sub dodie {
    my $message = $_[0];
    print($message . "\n");
    exit 1;
}

exec "diff $switches $predfile $file";
akavel
  • 4,789
  • 1
  • 35
  • 66
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried this script, mydiff reports "No such file or directory" for the element@@pred stuff. Will this only work in conjunction with the map file edit above? – chacmool Dec 17 '08 at 21:26
  • That will work only in dynamic view, where extended pathnames (@@\...) are accessible – VonC Dec 17 '08 at 21:47
  • Note: the script has nothing to do with the map file, which defines Type Merge Managers. – VonC Dec 17 '08 at 21:50
  • The map file only maps file types (as defined in the SERVER?) to diff programs. I have no control over how each file is mapped. I would like to set .SLN files to use the XML diff util, how can i achieve this ? – lysergic-acid Dec 21 '11 at 16:41
  • Thank you, this solved a persistent problem with the buggy XML diff/merge tool of ClearCase. – Frigo Aug 30 '12 at 12:48
  • I am tempted to downvote since this doesn't work (at least in my version of clearcase 8.0.1.10) for `xmerge`. Clearcase attempts to pass `-out` and `-base` arguments that of course are not recognized by p4merge. Unless there is a remedy for that that I don't know. – Stelios Adamantidis May 29 '17 at 12:59
  • @SteliosAdamantidis OK. I wrote that answer for ClearCase 7.x at the time. V8 was released in Oct. 2011. – VonC May 29 '17 at 13:10
  • I understand. Anyway, I might try a way to harness p4merge on 8.0 and post a separate answer. – Stelios Adamantidis May 29 '17 at 13:43
  • @SteliosAdamantidis Good idea. I am always surprised to still hear about ClearCase in 2017. – VonC May 29 '17 at 13:47
6

Another option is to use Git+ClearCase (or see this or this) and just diff with Git.

This is remarkably easy to set up and, in my experience, it actually hurts your brain less to use two VCS systems at once than to try to beat CC into being a 21st century tool.

Just think of Git as a bridge between CC and diff :-)

Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
  • 1
    I think this is a good idea also. I am more familiar with Mercurial and am going to try using that + cc in the next project. – chacmool Dec 18 '08 at 16:13
  • The links are all broken. Can you provide another one or, still better, write a self-answer to a new question? – Peter - Reinstate Monica May 09 '19 at 09:47
  • 1
    Sorry Peter, I wrote this answer 11 years ago and no longer use ClearCase. I've updated the answer with Wayback Machine links. I also have [another answer](https://stackoverflow.com/a/376281/17221) which would be pretty easy to turn into a script. If you're interested in bridging ClearCase and Git, it's pretty easy to do yourself, see [another StackOverflow answer here](https://stackoverflow.com/a/2345303/17221). Good luck! – Matt Curtis May 10 '19 at 23:04
5

It seems someone already thought about it on snip2code!
Here a tcsh bash script that does exactly what you want.

Custom-diff-tool-for-clearcase-object

As you can see the following is the key code to get the previous version of a given file:

cleartool descr -pred -short $1

Where $1 is the file name to compare.


#!/bin/tcsh -e
set _CLEARCASE_VIEW = `cleartool pwv -short -setview`
echo Set view: "$_CLEARCASE_VIEW"
set my_firstversion = ""
set my_secondversion = ""
set my_difftool = kdiff3

# check clearcase view
if ( "$_CLEARCASE_VIEW" == "** NONE **" ) then
  echo "Error: ClearCase view not set, aborted."
  exit -1
endif

if ( "$1" == "" ) then
  echo "Error: missing 1st file argument!"
  echo "Eg: `basename $0` file1.txt -> This will diff file1.txt with its previous version"
  echo "Eg: `basename $0` file1.txt file2.txt -> This will diff file1.txt and file2.txt"
  exit -1
endif  

set my_firstversion = "$1"
echo "my_firstversion=$my_firstversion"

if ( "$2" == "" ) then
  echo "No 2nd file passed, calculating previous version of $my_firstversion"
  set my_secondversion = $my_firstversion@@`cleartool descr -pred -short $my_firstversion`
else
  echo "Setting 2nd file to $2"
  set my_secondversion = "$2"
endif
echo "my_secondversion=$my_secondversion"

${my_difftool} ${my_firstversion} ${my_secondversion} &
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Dominique Terrs
  • 609
  • 8
  • 5
  • Seems really useful done in this way, most of all for the capability to consider all version trees and the runtime calculation of the previous version! – Cristiano Ghersi Sep 25 '13 at 14:00
5

Kdiff3 has built in integration. Open the tool - go to Settings --> Configure --> Integration and click the 'Integrate with ClearCase' button. This tool has excellent 3 way diff support, handles UTF-8 and with this automated integration you don't have to worry about element types etc. in the map file.

Bryji
  • 1,206
  • 1
  • 13
  • 19
3

Here's a link to the IBM docs on changing the ClearCase XML diff tool:

Changing the XML Diff/Merge Type Manager

http://www-01.ibm.com/support/docview.wss?rs=984&uid=swg21256807

3

I got another way working based on the suggestions here. I discovered the cleartool "get" command, so I execute this to get the previous version to a temp file:

cleartool get -to fname.temp fname@@predecessor

Then run my diff, and delete that file.

Thanks for all the suggestions.

chacmool
  • 1,357
  • 2
  • 16
  • 21
  • Good suggestion (+1), but you have to determine the 'predecessor' manually. I have updated my script to do that for you, even in a snapshot view, by using your 'cleartool get' command. – VonC Dec 20 '08 at 15:13
1

You could try using this trick:

  1. Create an empty file

    % touch empty

  2. Retrieve for version A

    % cleartool diff -ser empty File@@/main/28 > A

  3. Retrieve for version B

    % cleartool diff -ser empty File@@/main/29 > B

  4. Diff & profit!

    % your-diff-here A B

Put it in a script and make the options a bit more flexible and there you have it.

If you want you could easily snip the cleartool diff crud off with a little awk or cut or perl or your poison of choice.

Hooray for ClearCase!

Community
  • 1
  • 1
Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
1

To me this works nicely:

%vimdiff my_file.c my_file.c@@/main/LATEST
Zeppe
  • 205
  • 2
  • 4
0

I usually proceed like this.

For a unified diff cleartool diff -pred <my file>

For a graphical diff cleartool diff -pred -g <my file>

MZaragoza
  • 10,108
  • 9
  • 71
  • 116
olivier
  • 9
  • 1
0

I installed "WinMerge" (a free diff tool) and it installed itself as the clearcase diff tool. I'm not sure how it did that.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
0

WinMerge as mentioned automatically detects an install of ClearCase and modifies the map file in the Clearcase install path.

I have experienced issues were ClearCase will open its own diff tool instead because the WinMerge installation didn't change all neccessary line items. So it's a good idea to read the documentation for ClearCase so you can fix it manually if need be.

Oliver
  • 2,175
  • 3
  • 24
  • 31