Migrating Perforce to Plastic

I was tasked the other day with moving a project from Perforce to Plastic. There doesn't seem to be an official way of doing this, despite how much Plastic seems to be pushing for Perforce developers to move to the system. I could've just copied the files to a Plastic workspace and committed them, but I wanted to preserve the history too.

I managed to find a solution using an intermediary Git repository. You'll need:

  • Perforce (with p4 in the PATH)
  • Git
  • Python
  • Plastic (with cm in the PATH)

Perforce -> Git

First, we need to set up git-p4. It's an official Git command, but for me it wasn't included in the distribution of Git I had. Instead, I had to download the script directly and call it using python <path to git-p4.py>. If this is the case for you, substitute that for git p4.

Next, you're going to need to set some environment variables:

set P4PORT=<domain name and port to perforce server>
set P4USER=<username>
set P4PASSWD=<password>

I ran into some issues with Unicode files, and setting the charset seemed to work for me, so you might want to set this too:

set P4CHARSET=utf8

Before you import things to Perforce, you'll want to fix some file types. Git can't understand the "apple" file type in Perforce. It seems just changing every file in Perforce with an "apple" type to "binary" works fine.

Now it's time to move it to create a Git repo from Perforce:

git p4 clone <depot path>@all <path to new git repo>

For me, that meant:

git p4 clone //Gladiator/[email protected] Gladiator-git

Once you've done this, you should have a representation of your Perforce project in Git.

Git -> Plastic

Plastic has official support for importing from Git. First, you export your git repository using fast-export:

git fast-export --all -M --signed-tags=strip --tag-of-filtered-object=drop > ../git-fast-export.dat

Now you can simply import to Plastic with fast-import:

cm fast-import <workspace>@<server> ../git-fast-export.dat