Cloning a Partial Perforce Repo with git-p4

3.9k Views Asked by At

What is the proper method to do a selective import of a large Perforce repo?

The git-p4 docs mention that you can do a -//depot/main/ignore switch to filter directories. Would this be equivalent to running a git filter-branch to remove the same directories after a clone?

Additionally, it appears Perforce provides another feature called a "client" view. I have not used Perforce before, so I am a little unfamiliar with the usage model. My current understanding is that one would use p4 somehow to setup a proper client view before running git p4 clone. Does anyone have the complete details?

1

There are 1 best solutions below

6
On

A Perforce clientspec determines what parts of the Perforce repository are visible (and will be synced) to the Perforce client. The clientspec also provides a mapping from Perforce repository paths to local paths.

You can prune a Perforce client by selectively including parts of the Perforce repository. For example

//depot/main/path1/... //your-perforce-client/main/path1/...
//depot/main/path2/... //your-perforce-client/main/path2/...

will include only //depot/main/path1/ and //depot/main/path2/ and not //depot/main/path3/. As you've noted, you also can explicitly exclude paths. For example

//depot/main/path1/... //your-perforce-client/main/path1/...
-//depot/main/path1/foo/... //your-perforce-client/main/path1/foo/...

will include everything in //depot/main/path1/ except files under its foo subdirectory.

Depending on how your Perforce repository is structured and depending on what you want to include (or exclude), you potentially could tell git-p4 directly which parts of the Perforce tree you want to import:

git p4 clone --destination=/path/to/new/git/tree //depot/path1 //depot/path2

If you want to use exclusions or if you want to adjust how Perforce depot paths are mapped to local paths, you will need to add the --use-client-spec option. You can configure which Perforce client should be used by creating a .p4config file in your Git tree's parent directory containing:

P4CLIENT=YOUR_PERFORCE_CLIENT_NAME

and then setting an environment variable:

P4CONFIG=.p4config

Doing this will cause p4 to look for a .p4config file in the current directory (and then progressively search parent directories) for Perforce configuration data.

The files that will be imported will be the intersection of paths included by the Perforce clientspec and by the paths explicitly provided on the git p4 clone command-line.

(As you mentioned, git-p4 clone does allow excluding paths by prefixing them with -. However, I do not recommend doing this because that means that those paths will be excluded only on the initial import. If files in that path are touched in Perforce in the future, performing git p4 rebase/git p4 sync will pick up those changed files (unless you remember to explicitly exclude them on the command-line again). Initially importing using --use-client-spec, however, will set a flag in .git/config that allows it to be honored automatically when using git p4 rebase/git p4 sync in the future.)


One caveat is that performing a selective clone will add extra complication if someday you want to include other parts of the Perforce repository. See my answer to "Extending git-p4 clientspec after initial clone" if you need to do that.