Wed 15 Nov 2006
When I posted the first version of svk-init, my handy-dandy SVK initialisation script, I mentioned that I wanted to have the script figure out the short name for me, based on the repository URL. Promises made, promises kept:
#!/usr/bin/perl
use warnings;
use strict;
my($source, $short) = @ARGV;
unless(defined $short)
{
if($source =~ /^[^:]+://(.+)$/)
{
my @path = split('/', $1);
for(my $i = 1; $i < @path; $i++)
{
if($path[$i] eq 'branches' || $path[$i] eq 'tags' || $path[$i] eq 'trunk')
{
$short = $path[$i-1];
last;
}
}
# Fallback: use the last part of the path
$short ||= $path[-1];
}
}
unless(defined $short)
{
die('You need to provide a short name for the repository');
}
system("svk mirror $source //$short/main");
system("svk sync //$short/main");
system("svk cp //$short/main //$short/local "
."-m 'Creating //$short/local'");
system("svk co //$short/local ~/src/$short");
This allows me to give svk-init a repository URL of
http://svn.python.org/projects/python/trunk/
and have svk-init correctly come up with “python” as the short name.
Relatedly, SVK’s author, Chia-liang Kao mentioned in the comments that the first version of svk-init could be compressed to svk cp $source ~/src/$short, plus answering a few questions. I tried it out, and sure enough, it does indeed do the job. I’m going to stick with svk-init for two reasons: 1) svk cp uses a different mirror naming scheme, and 2) svk cp requires you to answer 3-4 questions, meaning I can’t start it up and forget it about it like I do svk-init.