November 12, 2013

Say Goodbye to p4 Edit

Healthcare
Traceability

Image: thehjoss via Flickr

I think 'p4 edit' is by far the most cursed Perforce command on Twitter. Folks coming from Subversion and Git are accustomed to an implicit checkout workflow, and being forced to ask the version control system for permission to change something is grating. Conveniently, Perforce supports implicit checkout as well! Let's take a look.

In Perforce your normal workflow for changing a file is:

p4 sync
p4 edit foo.c
vim foo.c
p4 submit –d “editing foo.c”

Subversion doesn’t track what files you’re working on, so the workflow is just:

svn update
vim foo.c
svn status
svn commit –m “editing a file”

Conveniently, if you want that same workflow in Perforce all you have to do is set the workspace options 'allwrite' and 'noclobber' and then you can run this sequence of commands:

p4 sync
vim foo.c
p4 reconcile
p4 submit –d “editing foo.c”

If you decide to go with this workflow I highly recommend upgrading to the 2013.2 server . It automatically looks for changed files before syncing if you are using an allwrite workspace and it adds support for detecting moves and renames in 'p4 reconcile'. I've changed most of my workspaces over to this and it is fantastic.

Now, I do want to point out that letting Perforce know what you’re up to has a lot of upsides. For one thing, you can see what other people are working on. And for another, it lets us support exclusive checkout – we can warn you if someone else is working on a file that’s tough to merge. Most importantly, we don't have to scan your machine when running 'p4 sync' and 'p4 reconcile' which is one of the reasons Perforce handles large files so well.

However, if the update-edit-commit workflow is your cup of tea, have at it!