Coding and keeping it safe.

This is a Lightroom post in the sense that it’s talking about coding plugins for Lightroom. If you’re not interested in coding, you can stop right here and keep 5 minutes of your life.

I’ve lost track of the number of versions of LRB Portfolio and other plugins I have on my drive, both as code, and compiled. I literally have folders of them. Why? Well, because I’ve lost my codebase before and had to redo an update from memory, way back in between version 1.1 and 1.2. I overwrote the code with complied versions by accident. That really sucked. I called myself obscene names, but I got over it.

Talking with other developers, I heard about different ways to manage code. One of them was Subversion, but it seemed too complex for the simple codebase I have. Coda, the software I use for coding plugins and websites, has subversion built it, but it seems really geared to websites, and not good for plugins. It may well be fine, but I couldn’t get my head around it. My interest was purely academic, and I’d no reason to find a particular product.

Then something terrible happened. Somewhere between LRB Portfolio 2.3 and 2.4, an entire block of code, in the main file of the plugin, got overwritten by text. I literally have no idea how it happened. I just opened the file to edit and half of it was gone. I was able to replace the bad bits with the 2.3 code, but all the new stuff was gone. That sealed the deal for me, I had to find a way to keep my code safe always, not just when an update was launched.

After much seeking, I found a really cool piece of software called Cornerstone, from Zennaware. It does full Subversion, but I only need a tiny part of the functionality. Normally you would use a server, but I’m just using a folder on my drive. The 15 day trial seemed more like 15 days of having it open, than 15 successive days. Still they proved I needed the program, so I parted with my $60 happily.

Here’s my workflow.

I have a repository on the drive and I have a working copy checked out. I do all my edits in Coda and Cornerstone keeps track, making new copies in the background as I save. I can always step back to a previous version at any time. When I get to a point where I want to test the plugin, I commit my changes. I can choose to add text to a log file, helping figure out which previous version I might need in the future. Next I select the working copy and click on the ‘Export’ button. I’ve set this up to create a copy in the Web Galleries folder of Lightroom. While the export is happening, I restart Lightroom. The export is fast, so when Lightroom reopens, I can immediately see the changes.

What’s great about this is that the version in Web Galleries is no longer a precious commodity. I simply export the current working copy. Because Coda is working on a safe copy, with automatic backup, this working copy is used to make the compiled version of the file for beta testing. I have a script that copies the folder specified, and tags .lrwebengine to the name. It then opens this new folder and compiles the 2 .lrweb files, leaving the plugin ready for distribution. At this point, there’s a compiled version, the working copy, the copy in Web Galleries, and of course all the versions in the repository. Because of this I can then continue working on the plugin, knowing that finally, the code is safe.

About Sean McCormack