两个分支之间的非集成变更列表

发布于 2024-09-16 16:48:31 字数 451 浏览 2 评论 0原文

当我在命令行中使用以下命令时,它会给出非集成更改列表的列表。

p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt

但是,当我在 Perl 脚本中使用此命令时,如下所示,它不会给出输出:

$cmd = system ("p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt");

命令行中的输出消息是一些错误,如下所示:

branch1, - all revision(s) already integrated.

问题是因为 date1 和 date2 之间使用了逗号?如何在 Perl 脚本中使用此命令?

when I use the following command in command line it's giving list of non integrated change lists.

p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt

But when I use this command in a Perl script as below it's not giving output:

$cmd = system ("p4 interchanges -t $branch1 @$date1, @$date2 $branch2 > changes.txt");

The output message in commandline is some error as given below:

branch1, - all revision(s) already integrated.

The issue is because of the comma used between date1 and date2? How to use this command in a Perl script?

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

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

发布评论

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

评论(2

夜还是长夜 2024-09-23 16:48:34

如果您要使用 Perl 进行大量 Perforce 操作,请尝试 P4Perl,它将 Perforce 包装在 Perl 原生 API 中。

从文档中抄袭,您的 system() 调用可以实现为:

use P4;
my $p4 = new P4;
$p4->SetClient( $clientname );
$p4->SetPort ( $p4port );
$p4->SetPassword( $p4password );
$p4->Connect() or die( "Failed to connect to Perforce Server" );

my $c = $p4->Run( "interchanges", "-t", $branch1, "@".$date1, "@".$date2, $branch2 );

$c 将包含每个未集成变更列表的数组引用。

If you're going to be doing a lot of Perforce with Perl, try the P4Perl, which wraps Perforce in a Perl-native API.

Cribbing from the documentation, your system() call could be implemented as:

use P4;
my $p4 = new P4;
$p4->SetClient( $clientname );
$p4->SetPort ( $p4port );
$p4->SetPassword( $p4password );
$p4->Connect() or die( "Failed to connect to Perforce Server" );

my $c = $p4->Run( "interchanges", "-t", $branch1, "@".$date1, "@".$date2, $branch2 );

$c will contain an array reference with each of the unintegrated changelists.

呢古 2024-09-23 16:48:33

这就是为什么打开 strict 如此重要的原因警告编译指示。字符串“@$date1”的含义并不像您想象的那样。它试图将 $data1 作为数组取消引用。因为 strict 不在,所以它会将 $date1 的内容视为符号引用。如果您打开了 strict,您会看到如下错误消息:

Can't use string ("2010-08-30") as an ARRAY ref while "strict refs" in use at script.pl line 10.

您可能应该这样说:

system "p4 interchanges -t $branch1\@$date1,\@$date2 $branch2 > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}

如果您期望 $branch1,您也可能会遇到问题>$date1 等是 shell 变量而不是 Perl 变量。在这种情况下你应该说:

system "p4 interchanges -t $ENV{branch1}\@$ENV{date1},\@$ENV{date2} $ENV{branch2} > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}

This is why it is so important to turn on the strict and warnings pragmas. The string "@$date1" does not mean what you think it does. It is trying to dereference $data1 as a an array. Because strict isn't on it is treating the contents of $date1 as a symbolic reference. If you had turned on strict you would have seen an error message like:

Can't use string ("2010-08-30") as an ARRAY ref while "strict refs" in use at script.pl line 10.

You should probably say this instead:

system "p4 interchanges -t $branch1\@$date1,\@$date2 $branch2 > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}

You may also have a problem if you expect $branch1, $date1, etc. to be shell variables instead of Perl variables. In that case you should say:

system "p4 interchanges -t $ENV{branch1}\@$ENV{date1},\@$ENV{date2} $ENV{branch2} > changes.txt";
if ($?) {
    die "saw exit code: ", $? >> 8;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文