TweetFollow Us on Twitter

(Avoiding) Subversion Troubles On Mac OS X

Volume Number: 25 (2009)
Issue Number: 01
Column Tag: Source Code Management

(Avoiding) Subversion Troubles On Mac OS X

A few simple steps can help dodge big Subversion headaches

by Ryan Wilcox

What is Subversion?

Subversion is a Source Control Management system with the goal to be a better CVS. Source control is critically important when two or more programmers are working together, as it allows those programmers to modify the same file together, both making changes to different parts of the file, then Subversion will merge their changes together. Single programmers can also use this tool so ensure the highest quality code goes into their product - if you look at the differences between the code on the server and the code on the local "sandbox", if your changes reduce the quality of the code you can simply revert.

This article isn't about the basics of how to use version control. Mike Zornek of Clickable Bliss explains, with video, the most basic concepts of Subversion in a screencast at http://blog.clickablebliss.com/2006/04/26/introduction-to-subversion-screencast/. MacTech covered this topic in Vol 22, Issue 11 (aka: the November 2006 issue), focusing on Xcode 2.0's built-in Subversion tools).

The command-line Subversion 1.4 client comes with Mac OS X 10.5 ("Leopard"). For Mac OS X 10.4 and earlier there are a number of solutions, from Installer.app installers (Martin Ott's Subversion packages are highly regarded, at http://homepage.mac.com/martinott/), or Fink/MacPorts, to compiling it from source. This author just uses MacPorts: sudo port install subversion in Terminal.app)

For those more graphically inclined, there are a few Mac OS X native options. There are a number of graphical clients for the Mac: the two newest options are Versions.app (http://www.versionsapp.com/) and Cornerstone (http://www.zennaware.com/cornerstone/), but there is also ZigVersion (http://zigzig.com/) and SvnX, (http://www.lachoseinteractive.net/en/community/subversion/svnx/). Xcode also has Subversion support built into the Project window, and SCPlugin (http://scplugin.tigris.org/) hot-wires Subversion capabilities right into the Finder (similar to a Windows client call TortoiseSVN, which gives Subversion capabilities to the Windows Explorer). In addition to these OS X only clients, there are several cross-platform ones that work in Mac OS X.

This article assumes you're using the command-line Subversion client, and while it tries to touch on global Subversion concepts and settings, they haven't been tested with any graphical client.

Protect Yourself: Ignore Icon Files (An Ounce Of prevention)

The transition to Mac OS X brought lots of good things, and several annoying things old time Mac users never had to deal with under the classic Mac OS. One of these is a problem with Subversion: the propensity of the Finder to write invisible (dot) files, like .DS_Store. .DS_Store files aren't so bad, but the Finder also writes custom icon information in an invisible file named "Icon", where the last character in the file name is a carriage return (CR). That Mac style return in the file name plays havoc with Subversion-and will actually corrupt your repository in such a way that nobody will be able to make new commits (or checkout, or update). So we need to tell Subversion to never allow Icon files.

Subversion has an "ignore these files" feature, set via the svn:ignore property (please see the Subversion book at http://svnbook.red-bean.com/ for more information on properties, and check out the section on Ignoring Unversioned Items). However, properties only apply in the directory in which they were set-they aren't applied recursively to child directories. The system could put an icon file anywhere, so this is no good. There is another solution: the Subversion Runtime Configuration Area.

When subversion runs for the first time it creates a .subversion folder in your home folder. This holds configuration information for your user on that machine. Any settings made here will apply to every subversion operation you, as that user, make. In particular, we want the global-ignore option.

$ cd ~/.subversion
$ pico config

(Pico is easy. If you have a favorite editor go use that.)

In this config file, find the global-ignores line and uncomment it. (A comment any line that begins with a pound sign.). There can be no leading whitespace on that line (I had to trim a bit off mine.)

With that line uncommented, add Icon* to the end. The items in this line are white-space delimited, so just go to the end of the line, type a space, and append Icon*. (Icon* because, remember, the Icon file actually has a return at the end!)

Icon Files (A Pound Of Cure)

If you do run into this problem, not to fear, it's solvable by ssh-ing into the Subversion server and executing a few svnadmin commands. Subversion has no way to totally nuke a file out of a repository, but we can create a new repository and actively filter out the stuff from the old repo that we don't want. It's worth noting here that svn remove just removes a file from the active line-up, but it's always there in the archives. (Except Icon files will still cause trouble in the archives, so we want to absolutely remove every last trace of it).

First, we need to dump the repository to a text file:

$ cd /path/to/your/repository
$ sudo svnadmin dump . > ~/repodump.dump

Secondly, we need to find where the Icon file is, so we can filter it out exactly. Use find, locate, or some other search mechanism on your local machine for this.

Now, for the filtering:

$ cat ~/repodump.dump | svndumpfilter exclude relative_path_to_Icon_file > ~/outDamnIconOut.dump

Two things are important here. Primarily, you must feed svndumpfilter your dump file-the path to your repository won't do. Secondarily, the exclude parameter takes a relative reference to the file. If you were in the root level of your sandbox (that is, your checked out files), it's the path you would enter to run a command on that Icon file.

svndumpadmin will report on what file it dumped, so if you don't see it, something went wrong (not the right path, perhaps??)

Now, move your old repository out of the way and use your new one, loaded with all your data except the Icon file:

$ mv /path/to/your/repository /path/to/your/repository_backup
??$ svnadmin create /path/to/your/repository
$ svnadmin load /path/to/your/repository < ~/outDamnIconOut.dump

The svndumpfilter section (found in Chapter 5 of the Subversion Manual) describes this command in depth, but this is what you need for now.

Bundles are just folders (with issues)

In the Mac OS X world many documents are actually packages: a cleverly disguised folder containing files. This goes into Subversion just fine: you simply need to add the bundle (which will recursively add all the files inside it), then add and remove the files inside the bundle as they are added or removed during work.

In order to make network operations fast, Subversion stores a copy of the revision (along with other meta-data), separate from the copy you see in your sandbox, on your hard drive. This means that Subversion can perform really fast diffs (without network access even!), and transmit just the differences to the server during a commit. Subversion writes a .svn folder with this copy, and other administrative information, for each folder in your sandbox. (CVS does a similar trick with "CVS" folders, so if this seems familiar, it is.

Cocoa document-based applications (or to quote from Apple's Document Based Application Overview: "When it saves a document, NSDocument creates a backup of the old file before it writes data to the new one. Backup files have the same name as the new file, but with a tilde just before the extension. Normally, if the write operation is successful, it deletes the backup file". Slightly confusing statement or not, the fact is a new file is created, with the new information, and the old version - with your oh so important .svn folder - is deleted forever.

Now, this isn't a problem for all Cocoa applications: some don't save using the normal NSDocument methods, some have a switch you can turn off this behavior with, or some explicitly work around it and keep .svn around (Omni Group products do this, as well as Interface Builder - starting with version 2.0 or so - and Xcode project files). But it can still be a problem where you don't expect it.

To see this behavior in action, all it takes is TextEdit (tested in Mac OS X 10.4 "Tiger" and Mac OS X 10.5 "Leopard"): create a file in that also has a picture in it. TextEdit will save this document as a .rtfd bundle. Now add this bundle to your repository (you don't have to commit it). Viewing the (visible and invisible) files in this bundle (via say ls Šla on the command line) will reveal a .svn folder. Reopen the document in TextEdit, make and save a change, and look at the contents of that bundle again: no .svn folder! (Clear away any svn confusion at this point with an svn remove -force filename.rtfd).

The simplest way to fix this is to rename the ruined file, update (causing Subversion to re-download the file), move the .svn directories from newly downloaded file to the ruined file, delete the downloaded file, rename the ruined file back to its original name, and use svn as normal. This method should work in the most common workflow, but it's not guaranteed to work in all obscure situations.

This technique was described on the Subversion mailing list in early 2003 (http://svn.haxx.se/dev/archive-2003-02/1321.shtml), and a small Python script (called fixsvn, written by Nicholas Riley) was attached to this message (and is, thankfully, available in the mailing list archive) that does this heavy lifting for you. Use it as so:

$ python /path/to/fixsvn ruined_file.rtfd

Since it was written in 2003, before Subversion was bundled with the OS, the path to svn is possibly wrong (depending on what version of Mac OS X you're running, and how you installed Subversion, if you had to), but that is easy to fix.

A more modern script (written in 2007, by Daniel A. Sadilek, as a script and also as an Automator action!) is available at http://sadilek.blogspot.com/2007/07/restore-svn-in-keynotepages-documents.html.

There is some hope on the horizon: the Subversion group is planning the next generation of meta-data storage, which will hopefully include storing the .svn files in one central location, instead of in every folder in the working copy. Not having .svn folders in bundles would solve a great headache for people who (for right now) have to use these scripts.

Even with these two scripts, and the new meta-data storage plan, dealing with bundles in Subversion is not exactly Mac-like, as the svn client will treat your bundle just like a folder: files added by your editing application (TextEdit, Keynote, etc) to the bundle must be svn added, and files deleted by these applications (without telling Subversion first) must be deleted with svn remove whatever.file -force (so Subversion doesn't go looking for the file to "helpfully" delete it for you). There is a bug in the Subversion bug tracker on wanting to treat bundles as "opaque collections", but in this author's opinion, it doesn't have much chance of being implemented (as it is a Mac OS X specific bug on a cross-platform project). However, if you're interested in this, it may be an interesting bug to follow, via the Subversion project's bug tracker.

Playing Well With Windows

In one way, text files are text files, readable on any platform. In practice, the differing line ending styles of PC and Mac/Unix complicates moving text files from one platform to another. Good source code editors respect and try to save text files with their original line endings, but sometime good intentions don't work out and the file is saved with a different set of line endings.

Subversion (and the standalone tool diff) respects different line endings to one extent: it will properly display the line endings (unlike, for example, opening a text file with Mac or Unix line endings with Window's Notepad, which displays the line endings as square boxes). However, this means that (if the line endings were accidentally changed by an editor) diff will show that the entire file has changed, making it impossible to see what changed by reading the diff. Committing a file like this means that (a) you've just changed the line endings on all your colleagues, and (b) obscured what changed in that revision and (c) make any future automatic merges impossible to automate. (At least pre Subversion 1.5, where you use the svnmerge.py tool for automatic merges from one branch to another).

One way to prevent this is to always run svn diff to validate what you are committing, then fixing the line endings as you need to. Which works, but why use a manual process when you can automate it?

Subversion to the rescue, which allows you to mark a file as needing processing on the client side to make sure line endings are consistent both on the client side (making sure that the file is written out with the native line endings of the platform), and on the server side (making sure that the file is saved on the server with only one set of line endings.

As a side-note: Subversion also lets you force the saved line endings, making the svn client write out line endings in a particular format (for example, forcing Subversion to use PC line endings on a .csv file, even on Mac OS X), via the svn:eol-style property. For example:

$ svn propset svn:eol-style native whatever.file

To use this, it must be applied to every new file in the repository, which is another thing Subversion can do automatically for you via its auto-properties feature, turned on via the config file in ~/.subversion (which we edited earlier in the article to ignore Icon files). Uncomment the enable-auto-props line, any file types you wish in the auto-props section of the config file, and when a file matches the appropriate expression the property specified is automatically added to the file.

On Windows, at least with TortoiseSVN, the Subversion Config(uration) file can be edited via the Settings dialog.

Of course, all the developers in your workgroup must also have made this change.

Concluding Thoughts

Subversion is an extraordinarily useful tool, and essential both to allow multiple programmers to work on a project together, and to ensure the consistency and quality of a product's source code. This author suggests doing a mini code-review before every check in: reading your diffs and removing debugging/tracing lines to make sure the code is of the best quality it can be.

However, like many things, Mac OS X throws us curve balls. From invisible files written by the Finder (that make your repository error on commit or checkout/update), to applications tossing important administrative directories, to cross-platform issues, there are tons of little "gotchas" waiting around the corner. With any luck, and the techniques from this article, you'll be able to avoid subversion troubles on Mac OS X.

References and Resources

Subversion Book: http://svnbook.red-bean.com/

List of Subversion clients: http://subversion.tigris.org/links.html#clients

NSDocument save behavior: http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/SubclassNSDocument.html

Subversion Mailing Lists: http://subversion.tigris.org/mailing-lists.html

Subversion Opaque Collection Bug: http://subversion.tigris.org/issues/show_bug.cgi?id=707

Svnmerge.py Tool: http://www.orcaware.com/svn/wiki/Svnmerge.py


Ryan Wilcox has been using Subversion as his primary source control system for the last 5 years, and has been on both ends, both client and server admin, of a Subversion setup. He can be found at: http://www.wilcoxd.com

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, donā€™t remind me I could currently buy him this month Iā€™m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly ā€œborrowedā€ many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »

Price Scanner via MacPrices.net

Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobileā€™s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13ā€³ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Appleā€™s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16ā€³ and 14ā€³ MacBook Pros along with 13ā€³ and 15ā€³ MacBook... Read more
Every model of Appleā€™s 13-inch M3 MacBook Air...
Best Buy has Apple 13ā€³ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13ā€³ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9ā€³ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Appleā€™s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&Tā€™s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Appleā€™s new 13ā€³ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13ā€³ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14ā€³ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more

Jobs Board

Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
*Apple* Systems Administrator - JAMF - Activ...
ā€¦**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.