Sunday, May 14, 2006

svn:externals and moving servers

Having just gone through the pain of moving our subversion repository off a machine that died on us, we discovered, or rather re-discovered the pain of (ab)using svn:externals to refer internally to the repository. i.e. we had a series of 'svn:externals' properties pointing to the server that went down.

To fix this I wrote the following ruby script to iterate over a checked-out repository and replace any existing svn:externals references to the current server with a new address. This post is really meant just to hold the ruby code I wrote so I can find it in the future ! :)

directory="";
Dir.foreach( directory ) do |x|
unless x== "." or x == ".." or x ==".svn"
if File.directory?( directory + "/" + x )
# Do the externals check here.
externals= `svn propget svn:externals "#{directory}/#{x}"`.split("\n");
if externals.length > 0
puts "-------------- #{directory}/#{x} -------- "

# Swap the bala for svn.
externals.collect! do |line|
line.gsub!( /oldServer:81/, 'newServer:81' );
end

# Write the new svn:externals property out to a file to use with the propset...
File.open("externals.txt","w") do |file|
file.puts( externals.join("\n") );
end

# Apply the new svn:externals property.
`svn propset svn:externals "#{directory}/#{x}" --file externals.txt`
end
manipulateDirectory( directory+"/"+x );
else
end
end
end

end

manipulateDirectory( "." ) ;