代码之家  ›  专栏  ›  技术社区  ›  Brian Carlton

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

  •  8
  • Brian Carlton  · 技术社区  · 16 年前

    9 回复  |  直到 16 年前
        1
  •  4
  •   Douglas Leeder    16 年前

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

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

    这是一个无休止的令人沮丧的问题。您应该能够通过以下操作从Windows命令行创建p4更改列表,而无需调用编辑器:

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

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

    p4 change -i < tempfile.txt
    

        3
  •  10
  •   tenpn    14 年前

    $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] }
    
        4
  •  5
  •   tenpn    14 年前

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

    p4 change
    

    创建待处理的更改列表。

    p4 reopen 
    

        5
  •  4
  •   bradym    12 年前

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

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

    这将:

    • 生成变更列表规范(“p4-change-o”)
    • 删除“在此处输入描述”行(“findstr-v”)

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

        7
  •  1
  •   Mike Johnson    14 年前
    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);
    
        8
  •  0
  •   Vissu    16 年前

    类型

    p4 submit
    

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

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

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

        9
  •  0
  •   JohPie    11 年前

    以下是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;
    }
    
    推荐文章