/[scripts]/trunk/svndump-move.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/svndump-move.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 47 by dpavlin, Fri Aug 3 17:52:21 2007 UTC revision 50 by dpavlin, Fri Aug 3 21:50:54 2007 UTC
# Line 2  Line 2 
2  use strict;  use strict;
3  use warnings;  use warnings;
4  use SVN::Dump;  use SVN::Dump;
5  use Shell qw/svnadmin cp find svn/;  use Shell qw/svnadmin cp find svn rm/;
6  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
7    use Data::Dump qw/dump/;
8    
9  my $base = shift @ARGV;  my $base = shift @ARGV;
10  $base ||= 'svn/';  $base ||= 'svn/';
11    
12    my $checkout = "$base/checkout";
13    
14    my $to_dump = 0;
15    
16  die "usage: $0 temp-base-directory (default: $base)\n" unless ( -e $base );  die "usage: $0 temp-base-directory (default: $base)\n" unless ( -e $base );
17    
18  my $mode = 'move';  my $mode = 'move';
19  my ( $from,     $to ) = ( "$base/from",         "$base/to/"             );  my ( $from,      $to      ) = ( "$base/from",     "$base/to/" );
20  my ( $fl,       $tl ) = ( "$base/from.lst",     "$base/to.lst"  );  my ( $from_list, $to_list ) = ( "$base/from.lst", "$base/to.lst" );
21    
22    sub rep_url {
23            return 'file:///' . abs_path(shift);
24    }
25    
26  sub create_list {  sub create_list {
27          my ( $dir, $path ) = @_;          my ( $dir, $path ) = @_;
28          my $list = svn('ls', '-R', 'file://' . abs_path($from));          my $list = svn('ls', '-R', rep_url($from));
29          open(my $fh, '>', $path) || die "can't create $path: $!";          open(my $fh, '>', $path) || die "can't create $path: $!";
30          print $fh $list;          print $fh $list;
31          close($fh);          close($fh);
# Line 27  sub create_list { Line 36  sub create_list {
36          warn "created: $path ", -s $path, "bytes\n";          warn "created: $path ", -s $path, "bytes\n";
37  }  }
38    
   
39  die "please copy repository on which to perfrom operation to $from\n" if ( ! -e $from );  die "please copy repository on which to perfrom operation to $from\n" if ( ! -e $from );
40    
41  warn "collect all paths from repository $from\n";  warn "##> collect all paths from repository $from\n";
42  create_list( $from, $fl );  create_list( $from, $from_list );
43    
44  if ( ! -e $tl ) {  if ( ! -e $to_list ) {
45          cp( $fl, $tl );          cp( $from_list, $to_list );
46          die "created $tl\nplease edit it to reflect new layout\n";          die "created $to_list\nplease edit it to reflect new layout\n";
47  } elsif ( ! -e $to ) {  }
48          svnadmin('create', $to);          
49          open(my $fh_in,  '-|', "svnadmin dump $from") || die "can't dump $from: $!";  my $map;
50          open(my $fh_out, '|-', "svnadmin load $to")   || die "can't load $to: $!";  my $mkdir;
51    
52          my $dump = SVN::Dump->new( { fh => $fh_in } );  open(my $fh_from, '<', $from_list ) || die "can't open $from_list: $!";
53    open(my $fh_to,   '<', $to_list   ) || die "can't open $to_list: $!";
54          warn "## $from -> $to\n";  while( my $path_from = <$fh_from> ) {
55            chomp($path_from);
56          while ( my $rec = $dump->next_record() ) {          my $path_to = <$fh_to> || die "list shorter, probably corrupt: $to_list\n";
57                  my $type = $rec->type();          chomp($path_to);
58                  if ( $type eq 'revision' && $rec->get_header( 'Revision-number' ) != 0 ) {          $map->{$path_from} = $path_to;
59                          my $to = 'dpavlin@rot13.org';          if ( $path_to =~ m{^(.+)/\Q$path_from\E$}) {
60                          $rec->set_property( 'svn:author' => $to );                  if ( ! $mkdir->{$1} ) {
61                            $mkdir->{$1}++;
62                            warn "##> will create $1 in new layout\n";
63                  }                  }
64                  warn "##> ", $rec->get_header('Node-path'), "\n";          }
65    }
66    
67    sub remap {
68            my ($path,$kind) = @_;
69            $path =~ s|/*$|/| if $kind && $kind eq 'dir';
70            if (defined( $map->{$path} )) {
71                    my $to = $map->{$path};
72                    warn "##> $path -> $to\n";
73                    return $to;
74            } else {
75                    warn "??> '$path'\n" if $path;
76                    return $path;
77            }
78    }
79    
80    warn "map = ",dump( $map ),$/;
81    warn "mkdir = ", dump( $mkdir ),$/;
82    
83    if ( -e $to ) {
84            #die "$to allready exists! remove it to re-create repository\n";
85            rm('-Rf',$to);
86    }
87    
88    svnadmin('create', $to);
89    open(my $fh_in,  '-|', "svnadmin dump $from") || die "can't dump $from: $!";
90    open(my $fh_out, '|-', "svnadmin load $to")   || die "can't load $to: $!";
91    open($fh_out, '>', "$base/to.dump") || die "can't dump to $base/to.dump: $!" if $to_dump;
92    
93    my $dump = SVN::Dump->new( { fh => $fh_in } );
94    
95    warn "## converting subversion repository $from -> $to\n";
96    
97    while ( my $rec = $dump->next_record() ) {
98    
99            if ( $rec->type() eq 'revision' && $rec->get_header( 'Revision-number' ) == 1 && $mkdir ) {
100                    # copy revision record
101                  print $fh_out $rec->as_string();                  print $fh_out $rec->as_string();
102                    # fetch dirs sorted by length
103                    foreach my $dir ( sort { length($a) <=> length($b) } keys %$mkdir ) {
104                            print $fh_out <<"__NODE_ADD_DIR__";
105    
106    Node-path: $dir
107    Node-kind: dir
108    Node-action: add
109    Prop-content-length: 10
110    Content-length: 10
111    
112    PROPS-END
113    
114    
115    __NODE_ADD_DIR__
116                            warn "##> inserted mkdir $dir\n";
117                    }
118                    next;
119            }
120    
121            my $path = $rec->get_header('Node-path');
122            my $kind = $rec->get_header('Node-kind');
123            if ( $path ) {
124                    $rec->set_header('Node-path', remap($path,$kind) );
125                    if ( $path = $rec->get_header('Node-copyfrom-path') ) {
126                            $rec->set_header('Node-copyfrom-path', remap($path,$kind) );
127                    }
128          }          }
129    
130            print $fh_out $rec->as_string();
131    }
132    
133    if ($@) {
134            warn "ERROR: $@\n";
135            warn "##> content imported into $to\n";
136            svn('ls','-R', rep_url($to));
137    }
138    
139    close($fh_in);
140    close($fh_out);
141    
142    if ( $to_dump ) {
143            svnadmin('verify',$to);
144  } else {  } else {
145          die "$to allready exists! remove it to re-create repository\n";          rm('-Rf', $checkout) if -e $checkout;
146            svn('co', rep_url($to), $checkout);
147  }  }

Legend:
Removed from v.47  
changed lines
  Added in v.50

  ViewVC Help
Powered by ViewVC 1.1.26