Fix Mac OS X svn ssl bug: "bad decompression"

Using SVN over SSL has been a real pain on Mac OS X (tested on snow leopard and lion).

The more 'heavy' SVN commands cause "SSL handshake failed: SSL error: bad decompression".

After some research this should be due a bug in the SSL library bundled with Apple's developer tools.

On the CollabNet forums someone suggested switching the standard http library called Neon for a new one called Serf written by some Google developers. This library should be really performant and handles SSL by itself.

Sadly the SVN tools from Apple don't come with the Serf library so we have to download a package which does.

The trick is the configure SVN to use the Serf library instead of the Neon library.

Owkay, so let's fix this step by step!

Step 1: check existing svn

Open up a terminal and check if the Serf library is for some reason already available by using following command:

svn --version

Screen_shot_2011-07-30_at_11

The library is available when you find "*ra_serf" in the list. If so, goto step 4.

Step 2: install svn package

*Snow Leopard

Download a SVN package and install. Remember the location where the svn tools will live. (note: i've used CollabNet but registration is required, others should do fine also I think)

*Lion

At the time of writing this post there seems to be no package available for Lion on CollabNet but you can with MacPorts. After upgrading to Lion, you'll also have to upgrade (sudo port -v selfupdate) or install MacPorts but you'll also need the latest Xcode (>= 4.1). You can install subversion with MacPorts with "sudo port install subversion". Following steps stay the same except the svn tools will live in another directory, for me that's /opt/local/bin.

Step 3: check for serf library

Let's check again if Serf's available. (note: replace path with your own install location)

/opt/subversion/bin/svn --version

Screen_shot_2011-07-30_at_14
As you can see, the Serf library is available!

Step 4: configure svn

Great, now we just have to configure your subversion settings so it will use the Serf library. 

open ~/.subversion/servers 

Search for the [global] section and add "http-library = serf" and save file.
Screen_shot_2011-07-30_at_14

Step 5: add new svn tools to path

To complete this, we add the freshly installed svn tools to the environment path.

open ~/.profile

And add following:

export PATH=/opt/subversion/bin:$PATH
 
Again, use the path to which you've installed the tools. Make sure the existing path gets appended so the new svn tools will take precedence over old ones.

Step 6: retry failed svn commands

After this, you should be able to execute svn command without the SSL "bad decompression" error.

If not, check if you really using the new svn tools and make sure they got exported to your environment. (note: initiate new terminal session so path changes take effect)

A good command to diagnose the problem in my case was doing a recursive svn list command.

svn ls -R https://svn.example.com/project/trunk

That's it! Enjoy!

Useful subversion alias

After using subversion from terminal for a while now, i've found following command so useful, I've turned it into an alias.

Add new files ready to commit

svn st | grep "^?" | awk '{print $2}' | xargs svn add

This command is a mouthful but saves you from adding each file individually.

When you want to use this alias you'll have to take care of the nested quotes and escape them.

alias sa='svn st | grep "^?" | awk '\''{print $2}'\'' | xargs svn add'

One could make several variations on this alias for svn remove, revert or others. You'll just have to change the grep and xargs arguments.

Terminal 'ls' alias

I use 'ls' very frequently in my mac os x or linux terminal. I've mostly been using 'ls -la' which stands for list the ALL files of current directory and put them nicely in columns.

A friend of mine gave me a nice tip yesterday. He also adds capital 'G' en 'h' as option. 'G' give you some nice colored or grouped list and 'h' makes sizes human readable.

Because remembering this or typing this over and over again is rather difficult, he also suggested to make an alias like so:

alias l='ls -alGh'

This way you only have to type 'l' and there you have your list, how convenient is that?

But when just executing this line in a terminal, it'll be forgotten next time you open one. In order for your aliases to be persistent (i.e. so they exist in all new Terminal windows) you need to put them in some file that gets read by your shell startup files (see "What startup files are read by the shell?"). So for example add the alias to the '~/.profile' file like so:

nano ~/.profile

You can add all kinds of aliases or functions to this file so they wil always be available for your account.