Version control
Designer offers a Python integration of the Perforce (P4) version control system.
The integration adds a custom ‘Version Control’ submenu to the contextual menu of packages in the Explorer, as well as custom icons to match the status of a package in P4.
Preparing P4
In P4V, make a note of the workspace name and path, as shown below:
In any text editor or IDE, open this script located in Designer’s installation: ‘tools/version_control/perforce.py’.
On line 19, edit the path to the location of the 'p4' executable on your system.
In the example below, this path is ‘c:/Program Files/Perforce/p4.exe’.
## Editable variables
cPerforceP4AbsPath = os.path.abspath("c:/Program Files/Perforce/p4.exe")
cVerbose = False
Setup in Designer
Version control is configured in the Project settings, which are available in Designer’s Preferences.
-
Go to ‘Edit > Preferences’
-
Go to ‘Projects’, select the target project file and go to the ‘Version Control’ tab
-
Check ‘Version Control Enabled’
-
Fill this information in the ‘Workspace’ section:
- Name: Enter the ‘Workspace Name’ you previously retrieved from P4V
- Path: enter the ‘Workspace Path’ you previously retrieved from P4V
Setting up actions
The actions will be available in the contextual menu of a package in the Explorer. There are predefined actions that match most Version Control tool concepts:
- All action labels can be changed as needed.
- All actions need a script in order to be valid.
You may use:
- one script per action
- one script for all actions
A starter script for all actions is available in Designer’s installation: ‘tools/version_control/perforce.py’.
- In the Actions group, click on the ‘…’ button of the Add action
- Select the following script in Designer’s installation: ‘tools/version_control/perforce.py’
- The script should automatically be set up for all other actions.
Setting up custom actions
As all version control tools are different and include many features, we allow the user to add custom actions.
- Click ‘Add item’
- Fill in the label of the new action, and set its script path
Setting up the script interpreter
- In the ‘Interpreters’ section, click ‘Add item’
- Set a script file extension or suffix, and the path to the interpreter executable
- Edit the perforce.py script to update the location of the ‘p4’ binary
How to use version control
-
Create a new package
-
Save the package under the ‘Workspace path’ directory
-
Click RMB on the package: you now have access to the ‘Version control’ submenu
-
Several actions are available, depending on the status of the package file in the workspace:
- Add: Mark the files as ‘ToAdd’
- Submit: Submit the selected packages. This action displays a dialog for specifying a change message (see below)
- Revert: Revert the modifications. This action displays a dialog for selecting the files to revert (see below)
- Checkout: Check the file out from the depot
- Get last version: Retrieve the latest version from the depot
- Refresh status: Refresh the package file status
table 0-row-2 0-border-0px 1-border-0px 2-border-0px html-authored no-header {modal="regular"}
{modal="regular"}
The package will have the following icons, depending on its status:
Note that an package which is not up to date is marked with a warning sign.
Action scripts
The command executed by each action is built thusly:
my_script WorkspaceName WorkspacePath ActionName[ActionArgs]
WorkspaceName: the name of the workspace
WorkspacePath: the path of the root directory of the workspace
ActionName: the name of the action:
- add: for the “Add” action
- checkout: for the “Checkout” action
- submit: for the “Submit” action
- revert: for the “Revert” action
- get_last_version: for the “Get Last Version” action
- get_status: for the “Get Status” action
The label is set up in the project settings, with ’ ’ character replaced by ‘_’ — E.g.: “My Action” => “My_Action”.
ActionArgs: arguments of the action:
- -desc: A description string used by ‘Submit’ action
- -files: A list of files
- -files_list: A text file that contains a list of files per line
get_status: Returns a value depending of the status of the specified file:
-
0: Undefined status
-
1: not in the depot
-
2: previous version (not up to date)
-
3: latest version (up to date)
-
4: checked out
-
5: marked for addition
-
other actions:
- 0: success
- other: error