You can use Perforce repositories with Sourcegraph by using the git p4 adapter, which creates an equivalent Git repository from a Perforce repository, and
src-expose, Sourcegraph’s tool for serving local directories.
Screenshot of using Sourcegraph for code navigation in a Perforce repository:
p4CLI configured to access your Perforce repository
git p4(see “Adding
git p4to an existing install”)
For each Perforce repository you want to use with Sourcegraph, follow these steps:
git p4 clone //DEPOT/[email protected](replace
//DEPOT/PATHwith the Perforce repository path).
src-expose servefrom the parent directory that holds all of the new local Git repositories.
src-exposeQuickstart to add the repositories to your Sourcegraph instance.
To update the repository after new Perforce commits are made, run
git p4 sync in the local repository directory. These changes will be automatically reflected in Sourcegraph as long as
src-expose serve is running.
We recommend running this command on a periodic basis using a cron job, or some other scheduler. The frequency will dictate how fresh the code is in Sourcegraph, and can range from once every 10s to once per day, depending on how large your codebase is and how long it takes
git p4 sync to complete.
src-expose: push the new Git repository to a code host
If you prefer, you can skip using
src-expose, and instead push the new local Git repository to a Git-based code host of your choice. For updates, you would run
git p4 sync && git push periodically.
If you do this, the repositories you created on your Git host are normal Git repositories, so you can add the repositories to Sourcegraph as you would any other Git repositories.
The instructions below will help you get Perforce repositories on Sourcegraph quickly and easily, while retaining all code change history. If your Perforce codebase is large enough that converting it to Git takes long enough to cause noticeable staleness on Sourcegraph, you can use
src-expose’s optional syncing functionality along with a faster fetching command (like
p4 sync instead of
git p4 sync) to periodically fetch and squash changes without trying to preserve the original Perforce history.
We intend to improve Sourcegraph’s Perforce support in the future. Please file an issue to help us prioritize any specific improvements you’d like to see.
[git-p4: depot-paths = "//guest/acme_org/myproject/": change = 12345].