创建具有多个文件规范的强制更改列表的简单方法

发布于 2024-08-07 14:12:54 字数 127 浏览 7 评论 0原文

我希望提交一个包含多个文件规范的更改列表,例如 ...this... ...file.h ...theother...Perforce 不会让我这样做。我可以从文件创建更改列表,但我确实希望有机会查看文件并输入评论。这是用于命令行解决方案。

I wish to submit a changelist with multiple filespecs, e.g. ...this... ...file.h ...theother.... Perforce won't let me. I could create a changelist from a file but I do want a chance to review the files and enter the comment. This is for a command-line solution.

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

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

发布评论

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

评论(9

乖乖哒 2024-08-14 14:12:54

如果您正在寻找 UNIX/*NIX 命令行解决方案,这将为您提供一个新的、干净的变更列表,并将编号保留在 $cl 中:

export cl=`p4 change -o | grep '^\(Change\|Client\|User\|Description\)' | p4 change -i | cut -d ' ' -f 2`

If you're looking for a UNIX/*NIX command line solution, this will give you a new, clean changelist and keep the number in $cl:

export cl=`p4 change -o | grep '^\(Change\|Client\|User\|Description\)' | p4 change -i | cut -d ' ' -f 2`
廻憶裏菂餘溫 2024-08-14 14:12:54

这是一个令人无限沮丧的问题。您应该能够从 Windows 命令行创建 p4 更改列表,而无需调用编辑器,方法是:

p4 change -o 
    | findstr /C:Description: /C:Change: /C:Client: /C:User: /C:Status: 
    | p4 change -i

返回字符串类似于“Change 1500 created”。您可以解析更改列表。然后,您可以通过执行

p4 edit -c 1500 //depot/base/...files.c

以下操作来添加单独的文件规范: 或类似的操作。该解决方案相对重要的问题是无法修改描述。或者,您可以使用必要的描述、更改、客户端等字符串创建临时文件,并通过以下方式创建更改列表:

p4 change -i < tempfile.txt

这看起来有点草率,但可能是脚本解决方案的最佳替代方案。

This is an endlessly frustrating problem. You should be able to create a p4 changelist from the Windows command line without invoking the editor by doing:

p4 change -o 
    | findstr /C:Description: /C:Change: /C:Client: /C:User: /C:Status: 
    | p4 change -i

The return string will be something like "Change 1500 created." which you can parse for the changelist. You could then add individual filespecs by doing:

p4 edit -c 1500 //depot/base/...files.c

Or something along those line. The relatively significant problem with this solution is the inability to modify the description. Alternatively, you can create a temp file with the requisite Description, Change, Client, etc strings and create the changelist via:

p4 change -i < tempfile.txt

This seems somewhat sloppier but may be the best alternative for scripting solutions.

老子叫无熙 2024-08-14 14:12:54

根据 Michael Gilbert 的回答,您可以在 powershell 中编辑描述,如下所示:

$newCLFormat = p4 change -o | select-string -pattern change, client, status
$newCLFormat += "Description: " + $myDescription
$newCLFormat | p4 change -i

要提取新的变更列表编号:

$newCLFormat | p4 change -i | select-string "\b(\d)+" | %{$_.matches[0].value}

现在必须有一种更快、更简洁的方法来提取该数字?

编辑:将 findstr 重构为选择字符串

编辑:检索更改列表的更简洁的方法:

$newCLFormat | p4 change -i | %{ $_.split()[1] }

Based on Michael Gilbert's answer, you can edit the description in powershell like so:

$newCLFormat = p4 change -o | select-string -pattern change, client, status
$newCLFormat += "Description: " + $myDescription
$newCLFormat | p4 change -i

To pull out the new changelist number:

$newCLFormat | p4 change -i | select-string "\b(\d)+" | %{$_.matches[0].value}

Now there's got to be a quicker, neater way to pull out that number?

edit: refactored findstr to select-string

edit: neater way to retrieve the changelist:

$newCLFormat | p4 change -i | %{ $_.split()[1] }
愁以何悠 2024-08-14 14:12:54

您可以创建一个待定更改列表,然后将所需的所有文件移至该列表中,然后再提交。即使是从命令行,尽管我发现 p4V 更容易使用此功能。

http://www.perforce.com/perforce/ doc.current/manuals/cmdref/change.html#1040665

p4 change

创建待处理的更改列表。

p4 reopen 

将文件移动到挂起的更改列表中。

You can create a pending changelist, then move all the files you want into that, before submitting it. Even from the command-line, although I find p4V easier to use for this functionality.

http://www.perforce.com/perforce/doc.current/manuals/cmdref/change.html#1040665

p4 change

to create a pending changelist.

p4 reopen 

to move files into the pending changelist.

嗫嚅 2024-08-14 14:12:54

我今天刚遇到这个问题,@Martin 的回答非常有帮助。我想创建一个带有描述的变更列表,而不是将其留空,所以我使用他的命令作为起点,并将其调整为:

export cl=`p4 change -o | sed 's/<enter description here>/"Change list description"/' | sed '/^#/d' | sed '/^$/d' | p4 change -i | cut -d ' ' -f 2`

I just came across this question today, and @Martin's answer was very helpful. I wanted to create a changelist with a description instead of leaving it blank, so I used his command as a starting point and tweaked it into this:

export cl=`p4 change -o | sed 's/<enter description here>/"Change list description"/' | sed '/^#/d' | sed '/^$/d' | p4 change -i | cut -d ' ' -f 2`
泪意 2024-08-14 14:12:54

这是一个单行代码,可以在 Windows cmd shell 中使用 p4 命令行和 Windows 标准 findstr 实用程序,并且不需要任何临时文件。

(p4 change -o | findstr /v "enter description here" & echo ○My new changelist)|p4 change -i

这将:

  • 生成变更列表规范(“p4change-o”)
  • 删除“在此处输入描述”行(“findstr-v”)
  • 附加新描述(“echo”)
  • 并最终创建新的变更列表(“p4change- i")

请注意,描述必须以制表符开头,即那个小“○”家伙。如果格式在进入 shell 的过程中中断,您可以使用 Alt-9 键入制表符。

Here is a one-liner that works in the Windows cmd shell with just p4 command line and the Windows-standard findstr utility and doesn't need any temporary files.

(p4 change -o | findstr /v "enter description here" & echo ○My new changelist)|p4 change -i

This will:

  • generate a changelist specification ("p4 change -o")
  • remove the "enter description here" line ("findstr -v")
  • append your new description ("echo")
  • and finally create the new changelist ("p4 change -i")

Note that the description must start with a tab character, which is that little "○" guy. If the formatting breaks en route to your shell, you can type a tab character with Alt-9.

年华零落成诗 2024-08-14 14:12:54
Here is my rough first pass at a Perl wrapper around p4 commands.
It would be most useful if you had a LOT of files to check in.
The form editor is NOT invoked.

#
# p4checkoutfiles.pl -
#
#       Will check out all files in current directory.
#       Print newly-created changelist number to display, for p4submitfiles.pl.
#       Optional command line parameter for Description, e.g. "Modifications from 07/25/2011".
#
#     USAGE:
#         1. Copy this script to a new folder.
#         2. Copy all files to be checked in to this same folder.
#         3. Run this script to check out all the files, as follows:
#
#               p4checkoutfiles.pl  <clientspec> <changelist_description>
#
#           For example:
#
#               p4checkoutfiles.pl ClientSpec-Mike "Modifications from 07/25/2011".
#
#
#         4. Manually copy these files over their older versions, in the correct workspace directory.
#         5. Run p4checkinfiles.pl.
#
# 

use strict;
use warnings;

################################################################################
# Save any command line parameters in local variables.
################################################################################

my $Client = shift;
die unless $Client;

my $ChangelistDescription = shift;


################################################################################
# Read default p4 form from pipe that executes p4 change command.
################################################################################

my $DefaultChangelistForm = "";

my $PrintDefaultChangelistCommand = "p4 change -o |";

open (PRINTDEFAULTCHANGELISTCOMMAND, $PrintDefaultChangelistCommand);

while (<PRINTDEFAULTCHANGELISTCOMMAND>)
{
    if (($_ !~ "Client") &&
        ($_ !~ "User") &&
        ($_ !~ "Status"))
    {
        $DefaultChangelistForm .= $_;
    }
}

# print "\$DefaultChangelistForm is: " . $DefaultChangelistForm; 

close PRINTDEFAULTCHANGELISTCOMMAND;



################################################################################
# Swap in any command line parameter for Description
################################################################################

if ($ChangelistDescription)
{
    $DefaultChangelistForm =~ s/<enter description here>/$ChangelistDescription/
}


################################################################################
# Write modified form values to disk, to be read by following p4 change -i.
################################################################################

open (FORMFORNEWCHANGELIST, ">formfornewchangelist.txt");
print FORMFORNEWCHANGELIST $DefaultChangelistForm;
close (FORMFORNEWCHANGELIST);



################################################################################
# Create new changelist using FORMFORNEWCHANGELIST.
# Read new changelist number from pipe that creates new changelist.
################################################################################

print "Creating new changelist...\n";

my $NewChangeList = "";
my $NewChangeListNumber = "";

my $CreateNewChangeListCommand = "";

$CreateNewChangeListCommand = "p4 -c ";
$CreateNewChangeListCommand .= $Client;
$CreateNewChangeListCommand .= " change -i < formfornewchangelist.txt |";

open (CREATENEWCHANGELISTCOMMAND, $CreateNewChangeListCommand);

while (<CREATENEWCHANGELISTCOMMAND>)
{
    if ($_ =~ "created")
    {
        # Save new change list number for below.
        $NewChangeListNumber = $_;
        print $_;
    }
}

close CREATENEWCHANGELISTCOMMAND;

################################################################################
# Save new changelist number to disk file newchangelistnumber.txt.
################################################################################

# Just parse numbers from string.
if ($NewChangeListNumber =~ /(\d+)/)
{
    $NewChangeListNumber = $1;
}


open (NEWCHANGELISTNUMBER, ">newchangelistnumber.txt");
print NEWCHANGELISTNUMBER $NewChangeListNumber;
close (NEWCHANGELISTNUMBER);


################################################################################
# Read workspace root from pipe that executes p4 client command.
################################################################################

my $WorkspaceRoot = "";

my $PrintClientCommand = "p4 client -o ";
$PrintClientCommand .= $Client;
$PrintClientCommand .= " |";

open (PRINTCLIENTCOMMAND, $PrintClientCommand);

while (<PRINTCLIENTCOMMAND>)
{
    # Save workspace root for edit command, below.
    if ($_ =~ "Root:")
    {
        $WorkspaceRoot = $_;

        # Just parse stuff after Root:
        if ($WorkspaceRoot =~ /Root:\s*(.*)/)
        {
            $WorkspaceRoot = $1;
        }
    }
}
close PRINTCLIENTCOMMAND;

die unless length($WorkspaceRoot) > 0;
# print "WorkspaceRoot is: " . $WorkspaceRoot;


################################################################################
# For each file (other than newchangelistnumber.txt),
# check out that file into newly-created changelist.
# NOTE: THIS CODE ASSUMES THE FILES HAVE ALREADY BEEN ADDED TO PERFORCE.
# Enhancement: Fix above constraint.
################################################################################

print "Checking out all files in this subdirectory already in Perforce...\n";

my $directory = '.';
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR))
{
    # We only want files
        next unless (-f "$directory/$file");

    # Skip text files.
    next if ($file =~ m/\.txt$/);

    # Skip Perl files.
        next if ($file =~ m/\.pl$/);

    my $CheckOutFileCommand = "";

    $CheckOutFileCommand = "p4 -c ";
    $CheckOutFileCommand .= $Client;
    $CheckOutFileCommand .= " edit ";
    $CheckOutFileCommand .= " -c " . $NewChangeListNumber . " ";
    $CheckOutFileCommand .= $WorkspaceRoot . "\\" . $file;
    $CheckOutFileCommand .= " | ";

    open (CHECKOUTFILECOMMAND, $CheckOutFileCommand);

    while (<CHECKOUTFILECOMMAND>)
    {
        print $_;
    }

    close CHECKOUTFILECOMMAND;

}

closedir(DIR);
Here is my rough first pass at a Perl wrapper around p4 commands.
It would be most useful if you had a LOT of files to check in.
The form editor is NOT invoked.

#
# p4checkoutfiles.pl -
#
#       Will check out all files in current directory.
#       Print newly-created changelist number to display, for p4submitfiles.pl.
#       Optional command line parameter for Description, e.g. "Modifications from 07/25/2011".
#
#     USAGE:
#         1. Copy this script to a new folder.
#         2. Copy all files to be checked in to this same folder.
#         3. Run this script to check out all the files, as follows:
#
#               p4checkoutfiles.pl  <clientspec> <changelist_description>
#
#           For example:
#
#               p4checkoutfiles.pl ClientSpec-Mike "Modifications from 07/25/2011".
#
#
#         4. Manually copy these files over their older versions, in the correct workspace directory.
#         5. Run p4checkinfiles.pl.
#
# 

use strict;
use warnings;

################################################################################
# Save any command line parameters in local variables.
################################################################################

my $Client = shift;
die unless $Client;

my $ChangelistDescription = shift;


################################################################################
# Read default p4 form from pipe that executes p4 change command.
################################################################################

my $DefaultChangelistForm = "";

my $PrintDefaultChangelistCommand = "p4 change -o |";

open (PRINTDEFAULTCHANGELISTCOMMAND, $PrintDefaultChangelistCommand);

while (<PRINTDEFAULTCHANGELISTCOMMAND>)
{
    if (($_ !~ "Client") &&
        ($_ !~ "User") &&
        ($_ !~ "Status"))
    {
        $DefaultChangelistForm .= $_;
    }
}

# print "\$DefaultChangelistForm is: " . $DefaultChangelistForm; 

close PRINTDEFAULTCHANGELISTCOMMAND;



################################################################################
# Swap in any command line parameter for Description
################################################################################

if ($ChangelistDescription)
{
    $DefaultChangelistForm =~ s/<enter description here>/$ChangelistDescription/
}


################################################################################
# Write modified form values to disk, to be read by following p4 change -i.
################################################################################

open (FORMFORNEWCHANGELIST, ">formfornewchangelist.txt");
print FORMFORNEWCHANGELIST $DefaultChangelistForm;
close (FORMFORNEWCHANGELIST);



################################################################################
# Create new changelist using FORMFORNEWCHANGELIST.
# Read new changelist number from pipe that creates new changelist.
################################################################################

print "Creating new changelist...\n";

my $NewChangeList = "";
my $NewChangeListNumber = "";

my $CreateNewChangeListCommand = "";

$CreateNewChangeListCommand = "p4 -c ";
$CreateNewChangeListCommand .= $Client;
$CreateNewChangeListCommand .= " change -i < formfornewchangelist.txt |";

open (CREATENEWCHANGELISTCOMMAND, $CreateNewChangeListCommand);

while (<CREATENEWCHANGELISTCOMMAND>)
{
    if ($_ =~ "created")
    {
        # Save new change list number for below.
        $NewChangeListNumber = $_;
        print $_;
    }
}

close CREATENEWCHANGELISTCOMMAND;

################################################################################
# Save new changelist number to disk file newchangelistnumber.txt.
################################################################################

# Just parse numbers from string.
if ($NewChangeListNumber =~ /(\d+)/)
{
    $NewChangeListNumber = $1;
}


open (NEWCHANGELISTNUMBER, ">newchangelistnumber.txt");
print NEWCHANGELISTNUMBER $NewChangeListNumber;
close (NEWCHANGELISTNUMBER);


################################################################################
# Read workspace root from pipe that executes p4 client command.
################################################################################

my $WorkspaceRoot = "";

my $PrintClientCommand = "p4 client -o ";
$PrintClientCommand .= $Client;
$PrintClientCommand .= " |";

open (PRINTCLIENTCOMMAND, $PrintClientCommand);

while (<PRINTCLIENTCOMMAND>)
{
    # Save workspace root for edit command, below.
    if ($_ =~ "Root:")
    {
        $WorkspaceRoot = $_;

        # Just parse stuff after Root:
        if ($WorkspaceRoot =~ /Root:\s*(.*)/)
        {
            $WorkspaceRoot = $1;
        }
    }
}
close PRINTCLIENTCOMMAND;

die unless length($WorkspaceRoot) > 0;
# print "WorkspaceRoot is: " . $WorkspaceRoot;


################################################################################
# For each file (other than newchangelistnumber.txt),
# check out that file into newly-created changelist.
# NOTE: THIS CODE ASSUMES THE FILES HAVE ALREADY BEEN ADDED TO PERFORCE.
# Enhancement: Fix above constraint.
################################################################################

print "Checking out all files in this subdirectory already in Perforce...\n";

my $directory = '.';
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR))
{
    # We only want files
        next unless (-f "$directory/$file");

    # Skip text files.
    next if ($file =~ m/\.txt$/);

    # Skip Perl files.
        next if ($file =~ m/\.pl$/);

    my $CheckOutFileCommand = "";

    $CheckOutFileCommand = "p4 -c ";
    $CheckOutFileCommand .= $Client;
    $CheckOutFileCommand .= " edit ";
    $CheckOutFileCommand .= " -c " . $NewChangeListNumber . " ";
    $CheckOutFileCommand .= $WorkspaceRoot . "\\" . $file;
    $CheckOutFileCommand .= " | ";

    open (CHECKOUTFILECOMMAND, $CheckOutFileCommand);

    while (<CHECKOUTFILECOMMAND>)
    {
        print $_;
    }

    close CHECKOUTFILECOMMAND;

}

closedir(DIR);
楠木可依 2024-08-14 14:12:54

类型

p4 submit

如果您的 P4EDITOR 是 vim,那么您将看到一个 vim 编辑窗口。转到命令模式并通过键入“

v followed by PgDown until you're done selecting all the files

Then do

:g!/.*pattern1.*#/d

”选择“Files:”行之后的所有行如果您有多个这样的模式,

:g!/.*pattern1.*#\|.*pattern2.*#\|.*pattern3.*#/d etc...

希望这会有所帮助!

Type

p4 submit

If your P4EDITOR is vim, then you will get a vim edit window. Goto command mode and select all the lines after the line "Files:" by typing

v followed by PgDown until you're done selecting all the files

Then do

:g!/.*pattern1.*#/d

If you have multiple patterns like this,

:g!/.*pattern1.*#\|.*pattern2.*#\|.*pattern3.*#/d etc...

Hope this helps!

梦归所梦 2024-08-14 14:12:54

这是 Maya (MEL) 的实现:

proc string jp_newChangeList()
{
    //This will return the file format as a string
    string $changelist = `system("p4 change -o || p4 change -i")`;
    //Break up the string by line
    string $breakChange[]; tokenize $changelist "\n" $breakChange;
    //Find the line called "enter description here" and edit it with your text (precede text with 4 SPACES to preserve format!!!)
    int $count = 0;
    int $mine = 0;
    for($lii in $breakChange)
    {
        $lii = `strip $lii`;
        if($lii == "<enter description here>") $mine = $count;
        $count++;
    }
    $breakChange[$mine] = "    User enters text for description here";
    //get a local dummy file location and call it "p4.txt". We will use this to generate a changelist
    $exampleFileName = ( `internalVar -userTmpDir` + "p4.txt" );
    $fileId=`fopen $exampleFileName "w"`;
    int $printCount = 0;
    //Print string array, one line at a time, until you pass the description string (leaving the "files" part unspecified)
    while($printCount <= $mine)
    {
        fprint $fileId ($breakChange[$printCount] + "\n");
        $printCount++;
    }
    //close the text file
    fclose $fileId;
    //Read the text file to return the changelist number 
    string $changelist = `system("p4 change -i < " + $exampleFileName)`;
    //Parse return statement to isolate changelist number
    string $changeNum[]; tokenize $changelist " " $changeNum;
    string $changeListNumber = $changeNum[1];
    return $changeListNumber;
}

Here's an implementation for Maya (MEL):

proc string jp_newChangeList()
{
    //This will return the file format as a string
    string $changelist = `system("p4 change -o || p4 change -i")`;
    //Break up the string by line
    string $breakChange[]; tokenize $changelist "\n" $breakChange;
    //Find the line called "enter description here" and edit it with your text (precede text with 4 SPACES to preserve format!!!)
    int $count = 0;
    int $mine = 0;
    for($lii in $breakChange)
    {
        $lii = `strip $lii`;
        if($lii == "<enter description here>") $mine = $count;
        $count++;
    }
    $breakChange[$mine] = "    User enters text for description here";
    //get a local dummy file location and call it "p4.txt". We will use this to generate a changelist
    $exampleFileName = ( `internalVar -userTmpDir` + "p4.txt" );
    $fileId=`fopen $exampleFileName "w"`;
    int $printCount = 0;
    //Print string array, one line at a time, until you pass the description string (leaving the "files" part unspecified)
    while($printCount <= $mine)
    {
        fprint $fileId ($breakChange[$printCount] + "\n");
        $printCount++;
    }
    //close the text file
    fclose $fileId;
    //Read the text file to return the changelist number 
    string $changelist = `system("p4 change -i < " + $exampleFileName)`;
    //Parse return statement to isolate changelist number
    string $changeNum[]; tokenize $changelist " " $changeNum;
    string $changeListNumber = $changeNum[1];
    return $changeListNumber;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文