[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Repos reorganizing with --parent-dir ?

From: Michael W Thelen <thelenm_at_cs.utah.edu>
Date: 2004-08-03 05:11:20 CEST

* Roland Philippsen <roland.philippsen@gmx.net> [2004-07-30 03:39]:
> Let me illustrate. I want to change this kind of layout
>
> svn/
> trunk/
> foo/
> bar/
> branches/
> foo/
> bar/
>
> so that it becomes:
>
> svn/
> foo/
> trunk/
> branches/
> bar/
> trunk/
> branches/

Here is a script I wrote a while back to do this very thing. It works
directly on a URLs, so each change creates a new revision. Change
$repos to the URL of your repository, and change $base to the "parent"
directory of the directories you want to move around (I can't tell if
that would be "/svn" or just "/" in your example). By default the
script will just print the commands it will run... if they look okay,
then change $REALLY_DO_IT to 1 instead of 0. Hope this is useful to
you!

#/usr/bin/perl

use warnings;
use strict;

my $REALLY_DO_IT = 0;
my $repos = 'http://path/to/repos';
my $base = '/parent/dir';
my %mkdir;

my %base = map {$_=>1} svn_ls($base);
for my $area (qw(trunk branches tags)) {
    my @tags = $area eq 'trunk' ? ('trunk') :
        map {"$area/$_"} svn_ls("$base/$area");
    for my $tag (@tags) {
        for my $project (svn_ls("$base/$tag")) {
            svn_mkdir("$base/$project") unless exists $base{$project} or
                exists $mkdir{"$base/$project"};
            svn_mkdir("$base/$project/$area") unless $area eq 'trunk' or
                exists $mkdir{"$base/$project/$area"};
            svn_mv("$base/$tag/$project", "$base/$project/$tag");
        }
    }
    svn_rm("$base/$area");
}

sub svn_ls {
    `svn ls $repos$_[0]` =~ /([^\/\s]+)/g
}

sub svn_mkdir {
    my ($dir) = @_;
    my $cmd = "svn mkdir $repos$dir -m 'create $dir'";
    if ($REALLY_DO_IT) { system $cmd; }
    else { print "$cmd\n"; }
    $mkdir{$dir} = 1;
}

sub svn_mv {
    my ($from, $to) = @_;
    my $cmd = "svn mv $repos$from $repos$to -m 'move $from to $to'";
    if ($REALLY_DO_IT) { system $cmd; }
    else { print "$cmd\n"; }
}

sub svn_rm {
    my ($dir) = @_;
    my $cmd = "svn rm $repos$dir -m 'delete $dir'";
    if ($REALLY_DO_IT) { system $cmd; }
    else { print "$cmd\n"; }
}

-- Mike

-- 
Michael W. Thelen
When everybody actually is out to get you, paranoia is just good thinking.
                -- Woody Allen

Received on Tue Aug 3 05:12:20 2004

This is an archived mail posted to the Subversion Users mailing list.