/[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 49 by dpavlin, Fri Aug 3 18:13:55 2007 UTC revision 50 by dpavlin, Fri Aug 3 21:50:54 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use SVN::Dump;  use SVN::Dump;
5  use Shell qw/svnadmin cp find svn rm/;  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 29  sub create_list { Line 38  sub create_list {
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  }  }
48                    
49  my $map;  my $map;
50    my $mkdir;
51    
52    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    while( my $path_from = <$fh_from> ) {
55            chomp($path_from);
56            my $path_to = <$fh_to> || die "list shorter, probably corrupt: $to_list\n";
57            chomp($path_to);
58            $map->{$path_from} = $path_to;
59            if ( $path_to =~ m{^(.+)/\Q$path_from\E$}) {
60                    if ( ! $mkdir->{$1} ) {
61                            $mkdir->{$1}++;
62                            warn "##> will create $1 in new layout\n";
63                    }
64            }
65    }
66    
67  open(my $fhf, '<', $fl ) || die "can't open $fl: $!";  sub remap {
68  open(my $fht, '<', $tl ) || die "can't open $tl: $!";          my ($path,$kind) = @_;
69  while( my $lf = <$fhf> ) {          $path =~ s|/*$|/| if $kind && $kind eq 'dir';
70          chomp($lf);          if (defined( $map->{$path} )) {
71          my $lt = <$fht> || die "list shorter, probably corrupt: $tl\n";                  my $to = $map->{$path};
72          chomp($lt);                  warn "##> $path -> $to\n";
73          $map->{$lf} = $lt;                  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 ) {  if ( -e $to ) {
84          #die "$to allready exists! remove it to re-create repository\n";          #die "$to allready exists! remove it to re-create repository\n";
85          rm('-Rf',$to);          rm('-Rf',$to);
# Line 56  if ( -e $to ) { Line 88  if ( -e $to ) {
88  svnadmin('create', $to);  svnadmin('create', $to);
89  open(my $fh_in,  '-|', "svnadmin dump $from") || die "can't dump $from: $!";  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: $!";  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 } );  my $dump = SVN::Dump->new( { fh => $fh_in } );
94    
95  warn "## $from -> $to\n";  warn "## converting subversion repository $from -> $to\n";
96    
97  while ( my $rec = $dump->next_record() ) {  while ( my $rec = $dump->next_record() ) {
98          my $type = $rec->type();  
99          if ( $type eq 'revision' && $rec->get_header( 'Revision-number' ) != 0 ) {          if ( $rec->type() eq 'revision' && $rec->get_header( 'Revision-number' ) == 1 && $mkdir ) {
100                  my $to = 'dpavlin@rot13.org';                  # copy revision record
101                  $rec->set_property( 'svn:author' => $to );                  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');          my $path = $rec->get_header('Node-path');
122          if ( $path && defined( $map->{$path} ) ) {          my $kind = $rec->get_header('Node-kind');
123                  my $to = $map->{$path};          if ( $path ) {
124                  warn "##> $path -> $to\n";                  $rec->set_header('Node-path', remap($path,$kind) );
125                  $rec->set_header('Node-path', $to);                  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();          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 {
145            rm('-Rf', $checkout) if -e $checkout;
146            svn('co', rep_url($to), $checkout);
147    }

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

  ViewVC Help
Powered by ViewVC 1.1.26