Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Any way to use a custom diff tool with cleartool/clearcase?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How to change default diff tools

You can specify an external diff tool by modifying the file map, in "c:program files ationalClearCaselibmgrs"

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          ....incleardiff.exe
text_file_delta   xcompare         ....incleardiffmrg.exe
text_file_delta   merge            ....incleardiff.exe
text_file_delta   xmerge           ....incleardiffmrg.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
"; }

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
"; }

# 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(/
/, $str1));
if($str1 =~ /View attributes: snapshot/sm) { $is_snapshot = 1; }

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

exec "diff $switches $predfile $file";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...