簡體   English   中英

使用多個文件規范創建perforce更改列表的簡便方法

[英]Easy way to create perforce changelist with multiple filespecs

我希望提交一個包含多個文件規范的更改列表,例如......這...... file.h ......其他.... Perforce不會讓我。 我可以從文件創建更改列表,但我確實希望有機會查看文件並輸入注釋。 這適用於命令行解決方案。

如果您正在尋找UNIX / * NIX命令行解決方案,這將為您提供一個新的,干凈的更改列表並將數字保存在$cl

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

這是一個無休止的令人沮喪的問題。 您應該能夠從Windows命令行創建p4更改列表,而無需通過執行以下操作來調用編輯器:

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

返回字符串將類似於“更改1500創建”。 您可以解析更改列表。 然后,您可以執行以下操作添加單個文件規范:

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

或者沿着那條線的東西。 該解決方案的相對重要的問題是無法修改描述。 或者,您可以使用必需的Description,Change,Client等字符串創建臨時文件,並通過以下方式創建更改列表:

p4 change -i < tempfile.txt

這似乎有點邋..但可能是腳本解決方案的最佳選擇。

根據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到select-string

編輯:檢索更改列表的更簡潔的方法:

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

我今天剛剛遇到這個問題,@ 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`

您可以創建掛起的更改列表,然后在提交之前將所需的所有文件移動到該列表中。 即使從命令行,我發現p4V更容易用於此功能。

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

p4 change

創建待定的更改列表。

p4 reopen 

將文件移動到掛起的更改列表中。

這是一個單行,在Windows cmd shell中只使用p4命令行和Windows標准的findstr實用程序,不需要任何臨時文件。

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

這將:

  • 生成更改列表規范(“p4 change -o”)
  • 刪除“在此輸入描述”行(“findstr -v”)
  • 追加你的新描述(“echo”)
  • 最后創建新的更改列表(“p4 change -i”)

請注意,描述必須以制表符開頭,即小“○”人。 如果格式化在途中轉移到shell,則可以使用Alt-9鍵入制表符。

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

類型

p4 submit

如果您的P4EDITOR是vim,那么您將獲得一個vim編輯窗口。 轉到命令模式並通過鍵入選擇“文件:”行之后的所有行

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

然后做

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

如果你有這樣的多個模式,

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

希望這可以幫助!

這是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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM