使用Perl脚本在Clearcase中更新checkedin文件的注释

时间:2012-11-01 22:40:58

标签: perl cygwin clearcase

我想用Perl脚本更新Clearcase中的checkedin文件的注释 如果我从命令行传递的注释不包含空格,则此脚本可以正常工作 但是当我使用带空格的注释时,我遇到了错误 -

  

错误:未找到路径名:“C:/Views/view1/some_dir/test.c @@ / main / dbg_test / 1

以下是脚本的命令行输入:

>>./appendcomments.pl dbg_test "\"scr1234, Test Scr\""  

这是我的代码。

if ($#ARGV != 1 )
{
    print "usage: addcomments.pl <base branch> <comment>\n";
    print "     For example addcomments.pl rel5.0 \"This is an example\"\n";
    exit;
}

my $base_branch =   $ARGV[0];
my $comment   =     $ARGV[1];

my ($output, @FILE_LIST, $file, $desr);

@FILE_LIST = `cleartool find -avobs -version "version(.../$base_branch/LATEST)" -print`;

FILE: foreach $file (@FILE_LIST) 
{
    $file =~ s/\\/\//g;
    $desr =`cleartool describe -fmt %Nc $file`;

    if ($desr !~ /scr\s*\#*\s*(\d+)/img)
    {
        chomp($file);
        $output = `cleartool chevent -c $comment -replace $file`; 
    }
}

2 个答案:

答案 0 :(得分:2)

在评论周围使用双引号(假设评论中没有双引号):

$output = `cleartool chevent -c "$comment" -replace $file`; 

如果您不必担心评论文本中出现双引号(或单引号或两者),那么您需要对变量注释做一些工作。因此,对于单引号评论,您应该考虑:

$comment =~ s/'/'\\''/g;  # Once, outside the loop

$output = `cleartool chevent -c '$comment' -replace $file`; 

在shell脚本中,$comment周围的单引号会阻止shell扩展变量,但这是Perl进行扩展。第一个替换用序列'\''替换注释字符串中的每个单引号。命令中的替换包围了整个单引号。这意味着有一个单引号字符串,每个'\''序列停止当前单引号字符串,输出转义单引号,然后启动一个新的单引号字符串,根据需要重复到评论末尾的单引号。

您说脚本是&#39; appendcomments.pl&#39;,但您在命令中使用-replace而不是-append。您的决定,但名称与行动不匹配。

答案 1 :(得分:1)

this threadthis thread一样,尝试转义这些引号:

$output = `cleartool chevent -c \"$comment\" -replace \"$file\"`; 

据说,实际问题是“C:/Views/view1/some_dir/test.c @@ / main / dbg_test / 1”将永远不存在(cygwin与否):ClearCase将访问 extended path 仅在动态视图(M:\...)中,而不是快照(C:\...),如本例所示,它使用动态视图。

更准确地说,来自“pathnames_ccase”:

  

从动态视图中,您可以使用此处描述的路径名表单作为采用路径名的任何cleartool命令的参数。
  从快照视图中,您可以使用VOB扩展路径名表单作为返回有关元素和版本信息的cleartool命令的参数(例如,describe,{ {1}},lslshistory)。此类操作不需要MVFS   但是,您不能使用VOB扩展路径名表单来检出未加载到视图中的元素版本。

     

Windows用户请注意:diff区分大小写。在cleartool子命令中,MVFS对象的路径名(包括MVFS命名空间中的视图专用文件)必须是大小写正确的。

所以在用引号进行战斗之前:

  • 使用dynamic view
  • 确保路径bis的大小写正确(在cygwin会话中使用简单的cleartool
  • 然后尝试你的ccperl脚本。