I had some big trouble with subversion today. I had upgraded to subversion 1.4 on both client and server a few days ago and today something went tits up with the repository on the server. I wont go into more detail here until I’ve reproduced and isolated the problem but suffice to say I deemed it worthwhile to try and restore my subversion repository from a recent dump file. Try was the operative word:
[schwa@umbriel] Dumps$ admin create test
[schwa@umbriel] Dumps$admin load test < dumpfile 'vnadmin: Invalid control character '0x0d' in path 'trunk/Path/To/Some/Directory/Icon<
My attempt to recover from a dumpfile failed because my repository contained a folder with a custom icon. Crickey. I find it odd that subversion lets me check these bad files into subversion in the first place. But whatever, I had to recover this dump file. Fortunately there is a tool called ‘dumpfilter’ that can be used to filter arbitrary paths in dump files. But after removing the first bad Icon file I found this particular repository had more than one. Instead of removing them by hand I started to write a shell script to automate the filtering process. Of course my shellfu is too low so I switched to Python:
#!/usr/bin/python
import commands
import re
import sys
theInputFile = sys.argv[1]
theOutputFile = None
if len(sys.argv) > 2:
theOutputFile = sys.argv[2]
thePattern = re.compile(r'^Node-path: (.+/Icon\r)$')
thePaths = [thePattern.match(theLine).group(1) for theLine in open(theInputFile) if thePattern.match(theLine)]
if theOutputFile == None:
print 'Found the following paths:'
for thePath in thePaths:
print '\t\'%s\'' % thePath.replace('\r', '\\r')
else:
theCommand = 'dumpfilter exclude %s < %s > %s' % (' '.join(['\'%s\" % thePath for thePath in thePaths]), theInputFile, theOutputFile)
print commands.getstatusoutput(theCommand)[1]
This script, when passed a path to an existing subversion dump file, will list all paths within the dump that contain custom icons. When passed a path to an existing dump file and the name of a new dump file it will remove all paths containing custom icons. You can then use this new dump file to populate your subversion repository without those pesky files. Update: From the comments, a link to Ryan Wilcox’s blog page concerning the problem (and a more detailed description of the solution): http://www.wilcoxd.com/blog/howto-get-out-the-icon-files-in-a-subversion-repo.html