p4bbi.py p4bbi.py - Import Baselines into a Perforce branching structure.


NAME

p4bbi.py - Import Baselines into a Perforce branching structure.


QUICK TEST - Mac/Linux Only

To make sure BBI is installed correctly, do like so:

  1. Step 1.

    Make sure 'p4' and 'p4d' executables are installed and in your PATH.

  2. Step 2.

    Create a /p4import directory writable by your user.

  3. Step 3.

    Extract p4bbi.tar.gz:

       cd /p4import
       gunzip p4bbi.tar.gz
       tar -xvpf p4bbi.tar
    
  4. Step 4.

    Prepare a Perforce server and baselines for import.

       cd /p4import
       ln -s p4bbi/test/baselines
       cd p4bbi/sample_cfg
       ./start_p4d.sh reset
    

    This creates a Perforce server on port 8674.

  5. Step 5.

    Run an import.

       cd /p4import/p4bbi
       ./p4bbi.py sample_cfg/p4config.test sample_cfg/FGS.bbi.cfg 
    
  6. Step 6.

    Review output. Run 'p4 changes -p 8674' and 'p4 describe 12', and the output should look something like this:

    $ p4 -p 8674 changes
    Change 12 on 2012/07/27 by p4import@p4import_ws 'Captured current state of devel'
    Change 11 on 2012/07/27 by p4import@p4import_ws 'Created FGS-2.0 development bra'
    Change 10 on 2012/07/27 by p4import@p4import_ws 'Rename makefile'
    Change 9 on 2012/07/27 by p4import@p4import_ws 'Imported baseline FGS-1.1.p3.'
    Change 8 on 2012/07/27 by p4import@p4import_ws 'Merged FGS-1.1.p2 back to MAIN.'
    Change 7 on 2012/07/27 by p4import@p4import_ws 'Result of merging FGS-1.1.p2 ba'
    Change 6 on 2012/07/27 by p4import@p4import_ws 'Imported baseline FGS-1.1.p2.'
    Change 5 on 2012/07/27 by p4import@p4import_ws 'Imported baseline FGS-1.1.p1.'
    Change 4 on 2012/07/27 by p4import@p4import_ws 'Created branch FGS-1.1.x-R.'
    Change 3 on 2012/07/27 by p4import@p4import_ws 'Import Baseline FGS-1.1.'
    Change 2 on 2012/07/27 by p4import@p4import_ws 'Created branch FGS-1.0.x-R.'
    Change 1 on 2012/07/27 by p4import@p4import_ws 'Import Baseline FGS-1.0.'
    
    $ p4 -p 8674 describe 12
    Change 12 by p4import@p4import_ws on 2012/07/27 13:35:50
    
            Captured current state of development files on FGS-2.0 branch.
    
    Affected files ...
    
    ... //ImportTest/Dev/FGS-2.0/fgs/src/CVS/cvs_file.txt#1 add
    ... //ImportTest/Dev/FGS-2.0/fgs/src/hello.c#2 edit
    ... //ImportTest/Dev/FGS-2.0/fgs/src/makefile_renamed#2 edit
    
    
    
    ==== //ImportTest/Dev/FGS-2.0/fgs/src/hello.c#2 (text) ====
    
    6c6
    <     printf ("\nHello, New World!\n");
    ---
    >     printf ("\nHello, Brave New World!\n");
    
    ==== //ImportTest/Dev/FGS-2.0/fgs/src/makefile_renamed#2 (text) ====
    
    10a11
    >       echo "Built $>"
    

SYNOPSIS

p4bbi.py [options] p4_config_file bbi_config_file

OR

p4bbi.py {-h|--help}


DESCRIPTION

Overview

This script creates a branching structure in Perforce, given a set of baselines and a defined branching structure.

This script must be run from a valid Perforce workspace on an existing server with the user and depot already configured.

Once the baselines are identified, the actual files from the baseline must be extracted from whatever version control system they are coming from, and put somewhere on a local disk. All baselines must be readily accessible by this script, so all operations necessary to extract baselines and get them to the locations defined in the config file must be done before this script is executed.

Perforce Information Config File Format

This config file has one section, a Header section.

Perforce Information Config File - Header Section

This contains name=value pairs, one entry per line. Values for P4PORT, P4CLIENT, and P4USER are required.

Be sure to set P4PASSWD=password in the environement, or run 'p4 login' for the given P4PORT/P4USER prior to running this script.

The following values are set in the Header section:

Branch Information Config File Format

The config file has two sections, a Baseline Definition section, and a Branching Information section.

Config File - Baseline Definition Section

This section defines all baselines that are available for import, those baselines having been extracted from (or available from) other version control systems. This section contains baseline definition entries of the form:

BASELINE|BaselineName|Directory

or

BASELINE|BaselineName|TarFile

or

BASELINE|BaselineName|GzippedTarFile

or

BASELINE|BaselineName|ZipFile

or

BASELINE|BaselineName|CMD:Command

where:

Config File Branching Info Section

There are six types of entries in the Branching Info section, update, branch, copy_merge, record_as_merged, and rename.

Branching Info - Update Entry

The Branch Update entry is of the form:

UPDATE|BaselineName|P4Dir|Description|Options

where:

The Update entry will result in a Perforce changelist being created that will apply files from a given baseline to a specified directory in Perforce.

For example, say you have two baselines named REL1.0 and REL1.1, and you want them checked into //import/MAIN. You might have:

UPDATE|REL1.0|//import/MAIN|Added REL1.0 to MAIN.

UPDATE|REL1.1|//import/MAIN|Updated MAIN with REL1.1.$NContains only deltas.

The first update would create a changelist consisting of adds of all files in REL1.0 to //import/MAIN. The second update would contain only the deltas between REL1.0 and REL1.1.

Branching Info - SafeUpdate Entry

The Branch SafeUpdate entry is of the form:

SAFEUPDATE|BaselineName|P4Dir|Description|Options

where:

The SafeUpdate entry will result in a Perforce changelist being created that will apply files from a given baseline to a specified directory in Perforce.

For example, say you have two baselines named REL1.0 and REL1.1, and you want them checked into //import/MAIN. You might have:

SAFEUPDATE|REL1.0|//import/MAIN|Added REL1.0 to MAIN.

SAFEUPDATE|REL1.1|//import/MAIN|Updated MAIN with REL1.1.$NContains only deltas.

The first update would create a changelist consisting of adds of all files in REL1.0 to //import/MAIN. The second update would contain only the deltas between REL1.0 and REL1.1.

It is important to note that the SAFEUPDATE command is parallel to but differs from the UPDATE in the treatment of files which have been deleted in the target location. The before a file is added it is checked against the identically named file in the depot and if the head revision is deleted the file is not included in the changelist and not added. SAFEUPDATE handles situations such as when code branched and developed is returned (copied back) to an ancestor branch where one or more of the files may have been deleted. By avoiding doing a blind copy of a deleted file and reporting the difference, a case-by-case review of files that are skipped can be done.

Branching Info - Branch Entry

The Branch entry is of the form:

BRANCH|SourcePath|TargetPath|Description|Options

where:

Branching Info - Copy Merge Entry

The Copy Merge entry is of the form:

COPY_MERGE|SourcePath|TargetPath|Description|Options

where:

Branching Info - Record As Merged Entry

The Record As Merged entry is of the form:

RECORD_AS_MERGED|SourcePath|TargetPath|Description

where:

Bear in mind that this operation runs a normal integration followed by a resolve with the accept yours option. It does not guarantee that the source and target paths will be identical afterwards, merely that the source path will have complete integration credit for merging to the target path. You may wish to follow this operation with an UPDATE to the target codeline with the actual state of the codeline after the merge was done.

Branching Info - Rename Entry

The Rename entry is of the form:

RENAME|SourcePath|TargetPath|Description

where:


OPTIONS

-v | --verbosity= level

Specify the verbosity level, from 1-3. 1 is quiet mode; only error output is displayed. 2 is normal verbosity; 3 is debug. The default for this program is 3.

-m | --mode= test

Specify No Op mode, indicating that the script should display what it would do with given arguments and config file, but take no action that affects data.

-r | --remove= rjd

Removes CVS/SVN/Mercurial/Git directories from the server after the import.

-c | --case= level

At level 1, detects and reports potential case sensitivity problems in imported data. At level 2, fails if these problems are detected. Files that have the same full path, ignoring case, are detected. This option is best effort; on case-insensitive platforms, some case sensitivity problems may already be obscured during baseline extraction.

-h | --help

Display the help.

ARGUMENTS

p4_config_file

Specify the absolute or relative path to the perforce connection config file.

The P4 configuration file is the settings file for connection to the Perforce server that is being updated with the BBI import. It contains name-value pairs (e.g. P4PORT=perforce:1666) to define the connection, workspace, and related details. In most cases, this file can be edited once and re-used.

bbi_config_file

Specify the absolute or relative path to the branching information config file.

The BBI configuration file contains the list of definitions and commands to perform to do the BBI import. Baselines define define the information sources (inputs) for the import and the other command types are the operations to be performed to apply the files to the target defined to complete importing of files. The commands are processed in the order they are read from the which does affect how content should be defined. Each command (line in the BBI configuration file) is a single change; lines are not combined into a compound update.


SOFTWARE PRECONDITIONS

The target Perforce server must be available and, the server must have the import Depot and workspace with a mapping to that depot created. The workspace line ending should be set to share. The workspace name should be the same as the one specified in the P4CONFIG file. If the server requires the user to login, that should be done before running the script.

The p4 and p4d binaries should be available in the path.


VALIDATOR

The validation script is p4bbi_validate.py. This tool will attempt to verify the BBI's actions. It will report any suspected discrepancies between the imported data and the baselines.

Run this script with the same inputs as the regular BBI, except for the -m | --mode flag. This option now specifies the level of checking the validator will perform. Current options are:

Note that the validator looks for changelist description in order to determine the revisions to verify. Changelist descriptions in the configuration file should be unique. (If there are no changes to submit for a command, the description is stored in a counter for later use.)


BEFORE STARTING

Setup steps:

  1. Confirm that you have 'python3' installed and available in the PATH. From the command line execute python3 -V; if you have a working Python it will print your Python version information.

  2. Confirm that your Perforce server is running and you can connect to it using P4. From the command line execute p4 info which if you have connectivity to your Perforce server will print information related to the connection.

  3. P4 Configuration File Settings
    1. Create an import user on the perforce server.
    2. Create a import workspace for the import user and ensure that its workspace root does not overlap any of your other directories.
    3. Update the P4 configuration file with your server port (P4PORT), user (P4USER), and workspace (P4CLIENT) values.

  4. Create your BBI configuration file(s), referencing the location of the files extracted from the source system in the BASELINE statements.


RETURN STATUS

Zero = success, non-zero = failure.


COPYRIGHT

Perforce Baseline and Branch Import Tool

Copyright (c) 2012 Perforce Software, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THIS SOFTWARE IS NOT OFFICIALLY SUPPORTED.

FEEDBACK

Please send any feedback to consulting@perforce.com.