Light Code Review with Shelving
Shelving is one of the most popular features Perforce ever introduced. Shelving work-in-progress is a great way to save what you're doing, try out new approaches to solving a problem, ask for code review, or hand off a task to someone else. The 2013.1 release introduces a couple of key improvements to shelving that make shelving a better solution to all of these problems, and particularly for shelving as a lightweight code review system.
Let's say I've made a couple of changes to two source code files in my workspace:
> vim sc* (make a couple of edits) > p4 reconcile ... //depot/main/src/scan.c#2 - opened for edit //depot/main/src/scan.h#1 - opened for edit
Now I want to ask Bruno to review my changes before I submit. I'll just shelve my changes and hand them off.
> p4 shelve Change 6 created with 2 open file(s). Shelving files for change 6. edit //depot/main/src/scan.c#2 edit //depot/main/src/scan.h#1 Change 6 files shelved. > p4 revert ... //depot/main/src/scan.c#2 - was edit, reverted //depot/main/src/scan.h#1 - was edit, reverted > p4 change 6 (make Bruno the owner instead of me)
Bruno can run a few commands to look at my work in progress.
> p4 diff2 "scan.c@=6" "scan.c#head" ==== //depot/main/src/scan.c#2 (text) - //depot/main/src/scan.c#2 (text) ==== content 4d3 < * shelved edit
Of course, the graphical tools in P4V, P4Eclipse, and P4VS provide easier ways to review the shelf. I'm just showing the command line for consistency.
At this point Bruno has a few options. He can assign it back to me, unshelve the changes for local building and testing, or just submit the shelf right away. That's one of the key improvements in the 2013.1 release: you can submit a shelved change directly, without getting the files into your workspace switching to the right branch.
> p4 submit -e 6 Submitting change 6. Locking 2 files ... edit //depot/main/src/scan.c#3 edit //depot/main/src/scan.h#2 Change 6 submitted.
That's it! At this point the shelf is cleaned up and the files are submitted.
Being able to submit a shelf directly is a real convenience. It makes shelves an even more useful container for work in progress - particularly if you're talking about a large amount of data in the shelf. There's no need to download and checkout the shelved files anymore.
In my next article I'll be writing about another big shelving improvement in the 2013.1 release. I've also written in the past about how you can use shelving as part of a more formal code review system. Take a look and see what shelving can do you for!