Indeed, when I design my killer language, the identifiers "foo" and "bar" will be reserved words, never used, and not even mentioned in the reference manual. Any program using one will simply dump core without comment. Multitudes will rejoice.
-- Tim Peters
Sometimes you wind up with changes in your source control system that shouldn't be in there, or you hit the submit button in perforce when you really meant just update the description. Anyways, you find yourself with a changelist that you want to roll back. If you're fast enough and noone manages to check in stuff on top of your changes this can be quite easy. There are several nifty sync options to changelists, to files only in changelists and the previous revision in the currently selected changelist. Even so, there is a little bit of work involved when you do this, as you need to then need to open the files for open and then resolve them automagically to accept yours.
A long while ago, I think on one of the first projects I wrote with perforce I had this nifty script that could revert changelists for me. I've forgotten what ticked me off that particular time and inspired me to write it, but it turned out to be pretty easy. Of course that script is now long gone. I recently ran into the same problem and realized that I had neither script nor an easy way in perforce to pull this off. So I wrote a new incarnation of the script. This time bigger! Better! More bugs! Eh. Ok, maybe more bugs since it tries to be smarter. And we all know how that goes... the road to hell is paved with seemingly nifty and smart scripts. With the risk of fire and brimstone and revert mayhem, here is the script in all it's glory.
The script is really not intended to be used as is on the commandline, although there is nothing stopping you. The real power comes from the built in hooks perforce have to add context sensitive commands to p4win, our favourite application. If you go in and add the following to the Tools->Customize menu (after you click Add) you will then have a very handy tool in the context menu like this.
Power to the people. Although with power there also comes responsibility. Computers just allows us to make our mistakes bigger, better and faster. In fact you can probably cause a lot of mayhem with this script if you don't think before you submit. So be careful. That said, it reduces this operation from maybe a couple of minutes for a large changelist to a couple of seconds depending on your perforce server's speed.
- Practical Perforce, a pragmatic take on how to manage and do common operations in perforce the way it was intended. Go with the flow and read it!
I updated the script with changes kindly submitted by Matt Zimmer, with the permission of Intuit. Some refactoring and features like:
- Changed default from overwrite to require manual resolve if later edits made to a file (you want to roll 28 back to 27 but there is a 29 in the depot).
- Added force flag to force overwrite (27 would overwrite 29 in the above scenario).
Thanks Matt for those changes! Now we can undo changes in perforce with ease :).
Small update to support filenames with spaces in them.
I've started a new open source project for all the perforce stuff I've written. Ironically it is hosted on a subversion server. You can see it over here: http://code.google.com/p/p4scripts.