有什么方法可以将自定义差异工具与cleartool/clearcase一起使用吗?

发布于 2024-07-10 16:14:55 字数 323 浏览 4 评论 0 原文

我想在使用 Clearcase 快照视图时使用我自己的差异。

据我所知,运行“cleartool diff”时无法指定 diff 工具,所以我想我可以运行类似“mydiff < ;在我的视图中修改了文件>”,但我对 ClearCase 的了解不够,无法找到要比较的“前身文件”。

有办法做到这一点吗?

忘记提及(直到现在,在阅读了处理 Windows 的前两个响应之后)这是在 Unix 上,并且不允许我破坏 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

神爱温柔 2024-07-17 16:14:55

如何更改默认 diff 工具

您可以通过修改文件 ma​​p 来指定外部 diff 工具,在“c:\program files\rational\ClearCase\lib\mgrs”中

Paul 建议的 WinMerge 实际上修改了该文件。

每条地图线都有 3 个部分:CC 文件类型、CC 操作和应用程序。

在映射文件中查找 text_file_delta 文件类型的部分。 在那里,您将找到 CC 操作比较、xcompare、合并和 xmerge 的行,如下所示:

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

您可以将它们替换为 您选择的 diff 工具的可执行文件


或者,一个简单的 diff 脚本

如果您想使用完整的命令行(我喜欢;-)),一点 ccperl 可以提供帮助:

#!/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";

警告:扩展路径名(@@\... ) 只能在动态视图 (M:\...) 中访问,而不能在快照视图 (c:\...) 中访问。

该脚本与 <上面提到的 code>map 文件:

  • 该文件定义了“类型合并管理器”。
  • 此脚本允许您在所需的任何文件上运行任何合并管理器,而无需读取任何映射文件来查找要使用的正确 diff exe。 。

在这里,您向脚本提供两种信息:文件(作为参数)和要运行的 diff exe(在脚本实现中:将 mydiff 替换为您想要的任何 diff exe)


或者,改进的 diff 脚本(也适用于静态/快照视图)

这是该脚本的一个版本,适用于快照和动态视图,

对于快照视图,我使用 chacmool 的建议:cleartool get

同样,您可以使用您选择的工具替换此脚本中包含的 diff 命令。

#!/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";

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";
月下伊人醉 2024-07-17 16:14:55

另一种选择是使用 Git+ClearCase (或参见 this) 并与 Git 进行比较。

这非常容易设置,而且根据我的经验,同时使用两个 VCS 系统实际上比尝试将 CC 打造成 21 世纪的工具对大脑的伤害要小。

只需将 Git 视为 CC 和 diff 之间的桥梁:-)

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 :-)

蹲在坟头点根烟 2024-07-17 16:14:55

似乎有人已经在 snip2code 上考虑过这个问题了!
这里有一个 tcsh bash 脚本,它完全可以满足您的需求。

自定义-diff-tool-for-clearcase -object

如您所见,以下是获取给定文件的先前版本的关键代码:

cleartool descr -pred -short $1

其中 $1 是要比较的文件名。


#!/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} &

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} &
小清晰的声音 2024-07-17 16:14:55

Kdiff3 具有内置集成。 打开工具--进入设置--> 配置--> 集成并单击“与 ClearCase 集成”按钮。 该工具具有出色的 3 路差异支持,可以处理 UTF-8,并且通过这种自动集成,您不必担心映射文件中的元素类型等。

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.

折戟 2024-07-17 16:14:55

根据这里的建议,我找到了另一种工作方式。 我发现了cleartool“get”命令,因此我执行此命令将以前的版本获取到临时文件:

cleartool get -to fname.temp fname@@predecessor

然后运行我的 diff 并删除该文件。

感谢所有的建议。

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.

没︽人懂的悲伤 2024-07-17 16:14:55

以下是有关更改 ClearCase XML diff 工具的 IBM 文档的链接:

更改 XML Diff/Merge Type Manager

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

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

静赏你的温柔 2024-07-17 16:14:55

您可以尝试使用 这个技巧

  1. 创建一个空文件

    % touchempty

  2. 检索版本 A

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

  3. 检索版本 B

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

  4. 比较与比较 利润!

    % your-diff-here A B

将其放入脚本中并使选项更加灵活,然后就可以了。

如果您愿意,您可以使用一点awkcutperl或您选择的毒药轻松地剪掉cleartool diff crud。

ClearCase 万岁!

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!

揽月 2024-07-17 16:14:55

对我来说这很有效:

%vimdiff my_file.c my_file.c@@/main/LATEST

To me this works nicely:

%vimdiff my_file.c my_file.c@@/main/LATEST
醉酒的小男人 2024-07-17 16:14:55

我安装了“WinMerge”(一个免费的 diff 工具),并将其自身安装为clearcase diff 工具。 我不知道它是怎么做到的。

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

_畞蕅 2024-07-17 16:14:55

如上所述,WinMerge 会自动检测 ClearCase 的安装并修改 Clearcase 安装路径中的映射文件。

我遇到过这样的问题:ClearCase 将打开自己的 diff 工具,因为 WinMerge 安装没有更改所有必要的行项目。 因此,最好阅读 ClearCase 的文档,以便您可以在需要时手动修复它。

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.

路还长,别太狂 2024-07-17 16:14:55

我通常都是这样进行的。

为了统一差异
cleartool diff -pred

用于图形差异
cleartool diff -pred -g <我的文件>

I usually proceed like this.

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文