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

Jump into one of Volkswagen's most...
We spoke about PUBG Mobile yesterday and their Esports development, so it is a little early to revisit them, but we have to because this is just too amusing. Someone needs to tell Krafton that PUBG Mobile is a massive title because out of all the... | Read more »
PUBG Mobile will be releasing more ways...
The emergence of Esports is perhaps one of the best things to happen in gaming. It shows our little hobby can be a serious thing, gets more people intrigued, and allows players to use their skills to earn money. And on that last point, PUBG Mobile... | Read more »
Genshin Impact 5.1 launches October 9th...
If you played version 5.0 of Genshin Impact, you would probably be a bit bummed by the lack of a Pyro version of the Traveller. Well, annoyingly HoYo has stopped short of officially announcing them in 5.1 outside a possible sighting in livestream... | Read more »
A Phoenix from the Ashes – The TouchArca...
Hello! We are still in a transitional phase of moving the podcast entirely to our Patreon, but in the meantime the only way we can get the show’s feed pushed out to where it needs to go is to post it to the website. However, the wheels are in motion... | Read more »
Race with the power of the gods as KartR...
I have mentioned it before, somewhere in the aether, but I love mythology. Primarily Norse, but I will take whatever you have. Recently KartRider Rush+ took on the Arthurian legends, a great piece of British mythology, and now they have moved on... | Read more »
Tackle some terrifying bosses in a new g...
Blue Archive has recently released its latest update, packed with quite an arsenal of content. Named Rowdy and Cheery, you will take part in an all-new game mode, recruit two new students, and follow the team's adventures in Hyakkiyako. [Read... | Read more »
Embrace a peaceful life in Middle-Earth...
The Lord of the Rings series shows us what happens to enterprising Hobbits such as Frodo, Bilbo, Sam, Merry and Pippin if they don’t stay in their lane and decide to leave the Shire. It looks bloody dangerous, which is why September 23rd is an... | Read more »
Athena Crisis launches on all platforms...
Athena Crisis is a game I have been following during its development, and not just because of its brilliant marketing genius of letting you play a level on the webpage. Well for me, and I assume many of you, the wait is over as Athena Crisis has... | Read more »
Victrix Pro BFG Tekken 8 Rage Art Editio...
For our last full controller review on TouchArcade, I’ve been using the Victrix Pro BFG Tekken 8 Rage Art Edition for PC and PlayStation across my Steam Deck, PS5, and PS4 Pro for over a month now. | Read more »
Matchday Champions celebrates early acce...
Since colossally shooting themselves in the foot with a bazooka and fumbling their deal with EA Sports, FIFA is no doubt scrambling for other games to plaster its name on to cover the financial blackhole they made themselves. Enter Matchday, with... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra available today at Apple fo...
Apple has several Certified Refurbished Apple Watch Ultra models available in their online store for $589, or $210 off original MSRP. Each Watch includes Apple’s standard one-year warranty, a new... Read more
Amazon is offering coupons worth up to $109 o...
Amazon is offering clippable coupons worth up to $109 off MSRP on certain Silver and Blue M3-powered 24″ iMacs, each including free shipping. With the coupons, these iMacs are $150-$200 off Apple’s... Read more
Amazon is offering coupons to take up to $50...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for up to $110 off MSRP, each including free delivery. Prices are valid after free coupons available on each mini’s product page, detailed... Read more
Use your Education discount to take up to $10...
Need a new Apple iPad? If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $100 off the... Read more
Apple has 15-inch M2 MacBook Airs available f...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
Mac Studio with M2 Max CPU on sale for $1749,...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M2 Max CPU in stock today and on sale for $250 off MSRP, now $1749 (12-Core CPU and 32GB RAM/512GB SSD). B&H offers... Read more
Save up to $260 on a 15-inch M3 MacBook Pro w...
Apple has Certified Refurbished 15″ M3 MacBook Airs in stock today starting at only $1099 and ranging up to $260 off MSRP. These are the cheapest M3-powered 15″ MacBook Airs for sale today at Apple.... Read more
Apple has 16-inch M3 Pro MacBook Pro in stock...
Apple has a full line of 16″ M3 Pro MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $440 off MSRP. Each model features a new outer case, shipping is free, and an... Read more
Apple M2 Mac minis on sale for $120-$200 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $110-$200 off MSRP this weekend, each including free delivery: – Mac mini M2/256GB SSD: $469, save $130 – Mac mini M2/512GB SSD: $689.... Read more
Clearance 9th-generation iPads are in stock t...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on clearance sale for starting at only $199 on their online store for a limited time. Sale prices for online orders only, in-store prices may vary... Read more

Jobs Board

Senior Mobile Engineer-Android/ *Apple* - Ge...
…Trust/Other Required:** NACI (T1) **Job Family:** Systems Engineering **Skills:** Apple Devices,Device Management,Mobile Device Management (MDM) **Experience:** 10 + Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Full Time (80 hrs/pay period) Evenings General Summary 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
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
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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.