Fast Subversion Update on a Rarely Updated Large Third Party Repository
I have a project with a large repository, which contains a lot of ThirdParty sources and binaries, that are seldom updated. While subversion might not be the best suited tool for the job, the size of that repository is not insane enough to consider using something else… yet!
The problem with that rarely updated large repository is that performing an svn update
on it can take quite a while even though there are no updates to perform. The reason is that subversion checks that no files are missing on the local checkout directory, because you can perform non recursive partial checkouts or updates, or potentially alter the whole structure after a checkout.
Nevertheless, if all you do is mirror the subversion directory content on your drive, you may have a faster option than svn update
. You can use svn info
to compare the local revision of your checkout to the latest available version on the server. If the revisions match it means your repository is up to date and you can avoid the costly svn update
.
I regularly use a powershell script to automate that process.
Powershell Script
# Set your svn path
$Svn = "svn.exe"
trap {
Write-Error "$_.Exception.GetType().FullName + $_.Exception.Message"
}
if ($args.length -ne 1) {
throw "Invalid arguments"
}
$source_path = $args[0]
$local_info = & $Svn info $source_path
if ($LastExitCode -ne 0) {
throw "Local svn info failed"
}
$local_revision = $local_info | %{ if ($_.startsWith("Revision")) { Write-Output $_ } } | %{ Write-Output $_.substring($_.indexOf(": ")+2) }
$url = $local_info | %{ if ($_.startsWith("Repository Root")) { Write-Output $_ } } | %{ Write-Output $_.substring($_.indexOf(": ")+2) }
$remote_info = & $Svn info $url
if ($LastExitCode -ne 0) {
throw "Remote svn info failed"
}
$remote_revision = $remote_info | %{ if ($_.startsWith("Revision")) { Write-Output $_ } } | %{ Write-Output $_.substring($_.indexOf(": ")+2) }
if ($local_revision -ne $remote_revision)
{
svn update $source_path
}
else
{
Write-Host "Up to date"
}