A touch of coolness

Running svn info from inside your project’s Subversion working directory will produce output similar to:

Path: .
URL: http://svn.rockblood.com/solo/trunk
Repository UUID: 3b82abcc-450f-0410-a6ff-cb6cb9f014c2
Revision: 189
Node Kind: directory
Schedule: normal
Last Changed Author: george
Last Changed Rev: 189
Last Changed Date: 2006-09-09 00:19:04 +0100 (Sat, 09 Sep 2006)

At a first glance, there’s nothing special about this piece of information. Look closer, though, and you’ll notice it’s actually a YAML document.

A touch of YAML.load(execute("svn info")) in Ruby, and we’re in business. Another application’s output becomes a hash, array, or object in a matter of one single line of code.

I haven’t come up with the idea, by the way, just stumbled upon it whilst going through the code of the Rails continuous_builder plugin, so respect due.

Also, I’m not so sure if the SVN guys had that in mind when they had the info command output in such a format. Does anyone know if it is intentional or just a coincidence?

The possibilities of standardizing your app’s output in such a manner are vast and I know how my app’s standard out is going to look like from now on.

5 Responses to “A touch of coolness”

  1. James Fairbairn Says:

    Of course SVN’s output, like that of CVS before it, was meant from the beginning to be very structured, and therefore machine readable. I doubt it was intended to be YAML any more than HTTP headers were. But it’s a neat hack anyway.

  2. Luke Redpath Says:

    Its very cool, I discovered this a while back. Here’s a little snippet I used in a project to display the current svn revision on the page footer in development mode:

    http://www.bigbold.com/snippets/posts/show/2374

  3. trans Says:

    How fortuitous ;-)
    I agree and I’ve been generally doing this myself for some time. Actaully I think it’s one of those things that just clicks after a while of using YAML and writing CLI tools. Recently however I started taking it a step further, expirementing with accepting YAML as command line argument:

    foo –x [a,b] –y {a: 1, b: 2}

    Would become:

    x:
    - a
    - b
    y:
    a: 1
    b :2

    T.

  4. topfunky Says:

    Now only if svn log was also formatted as YAML…

  5. Chris Says:

    Alternatively, you could just use the subversion bindings for ruby to get this information via the API - rather than using an exec & parse output hack.