/[svn2cvs]/trunk/svn2cvs.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/svn2cvs.pl

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

revision 30 by dpavlin, Mon Aug 20 08:37:22 2007 UTC revision 36 by dpavlin, Fri Sep 7 16:53:56 2007 UTC
# Line 20  use XML::Simple; Line 20  use XML::Simple;
20  # do we want to sync just part of repository?  # do we want to sync just part of repository?
21  my $partial_import = 1;  my $partial_import = 1;
22    
23    # do we want to add svk-like prefix with original revision, author and date?
24    my $decorate_commit_message = 1;
25    
26  if (@ARGV < 2) {  if (@ARGV < 2) {
27          print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n";          print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n";
28          exit 1;          exit 1;
# Line 222  if (! $xml->{'logentry'}) { Line 225  if (! $xml->{'logentry'}) {
225          exit 0;          exit 0;
226  }  }
227    
228  # check if file exists in CVS/Entries  # my ($dir,$file) = dir_file($path);
229  sub in_entries($) {  sub dir_file($) {
230          my $path = shift;          my $path = shift;
231          if ($path !~ m,^(.*?/*)([^/]+)$,) {          if ($path !~ m,^(.*?/*)([^/]+)$,) {
232                  die "can't split '$path' to dir and file!";                  die "can't split '$path' to dir and file!";
# Line 232  sub in_entries($) { Line 235  sub in_entries($) {
235                  if ($d !~ m,/$, && $d ne "") {                  if ($d !~ m,/$, && $d ne "") {
236                          $d .= "/";                          $d .= "/";
237                  }                  }
238                  open(E, $d."CVS/Entries") || return 0;                  return ($d,$f);
239                  while(<E>) {          }
240                          return(1) if (m,^/$f/,);  }
241    
242    # return all files in CVS/Entries
243    sub entries($) {
244            my $dir = shift;
245            die "entries expects directory argument!" unless -d $dir;
246            my @entries;
247            open(my $fh, "$dir/CVS/Entries") || return 0;
248            while(<$fh>) {
249                    if ( m{^D/([^/]+)}, ) {
250                            my $sub_dir = $1;
251                            warn "#### entries recurse into: $dir/$sub_dir";
252                            push @entries, map { "$sub_dir/$_" } entries("$dir/$sub_dir");
253                            push @entries, $sub_dir;
254                    } elsif ( m{^/([^/]+)/} ) {
255                            push @entries, $1;
256                    } elsif ( ! m{^D$} ) {
257                            die "can't decode entries line: $_";
258                  }                  }
                 close(E);  
                 return 0;  
259          }          }
260            close($fh);
261            warn "#### entries($dir) => ",join("|",@entries);
262            return @entries;
263    }
264    
265    # check if file exists in CVS/Entries
266    sub in_entries($) {
267            my $path = shift;
268            my ($dir,$file) = dir_file($path);
269            open(E, "$dir/CVS/Entries") || return 0;
270            while(<E>) {
271                    return(1) if (m,^/$file/,);
272            }
273            close(E);
274            return 0;
275  }  }
276    
277  cd_tmp;  cd_tmp;
# Line 254  foreach my $e (@{$xml->{'logentry'}}) { Line 287  foreach my $e (@{$xml->{'logentry'}}) {
287          my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!";          my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!";
288          my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!";          my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!";
289          do {          do {
290                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {       # vim fix
291                          $SVNREP = $1 . $SVNREP;                          $SVNREP = $1 . $SVNREP;
292                  } elsif ($e->{'paths'}->{'path'}->[0]->{'copyfrom-path'}) {                  } elsif ($e->{'paths'}->{'path'}->[0]->{'copyfrom-path'}) {
293                          print "NOTICE: copyfrom outside synced repository ignored - skipping\n";                          print "NOTICE: copyfrom outside synced repository ignored - skipping\n";
# Line 270  foreach my $e (@{$xml->{'logentry'}}) { Line 303  foreach my $e (@{$xml->{'logentry'}}) {
303          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});
304          my @commit;          my @commit;
305    
306            my $msg = $e->{'msg'};
307            $msg =~ s/'/'\\''/g;    # quote "
308    
309            $msg = 'r' . $rev . ' ' . $e->{author} . ' | ' . $e->{date} . "\n" . $msg if $decorate_commit_message;
310    
311            sub cvs_commit {
312                    my $msg = shift || die "no msg?";
313                    if ( ! @_ ) {
314                            warn "commit ignored, no files\n";
315                            return;
316                    }
317                    log_system("$cvs commit -m '$msg' '".join("' '",@_)."'", "cvs commit of ".join(",",@_)." failed");
318            }
319    
320          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
321                  my ($action,$path) = ($p->{'action'},$p->{'content'});                  my ($action,$path) = ($p->{'action'},$p->{'content'});
322    
# Line 293  foreach my $e (@{$xml->{'logentry'}}) { Line 340  foreach my $e (@{$xml->{'logentry'}}) {
340                  my $msg = $e->{'msg'};                  my $msg = $e->{'msg'};
341                  $msg =~ s/'/'\\''/g;    # quote "                  $msg =~ s/'/'\\''/g;    # quote "
342    
343                  if ($action =~ /M/) {                  sub add_path {
344                          if ( in_entries( $path ) ) {                          my $path = shift || die "no path?";
345                                  print "svn2cvs: modify $path -- nop\n";          
                         } else {  
                                 print "WARNING: modify $path which isn't in CVS, adding...\n";  
                                 log_system("$cvs add '$path'", "cvs add of $path failed");  
                         }  
                 } elsif ($action =~ /A/) {  
346                          if (-d $path) {                          if (-d $path) {
347                                  add_dir($path, $msg);                                  add_dir($path, $msg);
348                          } elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") {                          } elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") {
# Line 310  foreach my $e (@{$xml->{'logentry'}}) { Line 352  foreach my $e (@{$xml->{'logentry'}}) {
352                          } else {                          } else {
353                                  in_entries($path) || log_system("$cvs add '$path'", "cvs add of $path failed");                                  in_entries($path) || log_system("$cvs add '$path'", "cvs add of $path failed");
354                          }                          }
355                    }
356    
357                    if ($action =~ /M/) {
358                            if ( in_entries( $path ) ) {
359                                    print "svn2cvs: modify $path -- nop\n";
360                            } else {
361                                    print "WARNING: modify $path which isn't in CVS, adding...\n";
362                                    add_path($path);
363                            }
364                    } elsif ($action =~ /A/) {
365                            add_path($path);
366                  } elsif ($action =~ /D/) {                  } elsif ($action =~ /D/) {
367                          if (-e $path) {                          if (-e $path) {
368                                  unlink $path || die "can't delete $path: $!";                                  if ( -d $path ) {
369                                  log_system("$cvs delete '$path'", "cvs delete of $path failed");                                          warn "#### remove directory: $path";
370                                            my @sub_commit;
371                                            foreach my $f ( entries($path) ) {
372                                                    $f = "$path/$f";
373                                            if ( -f $f ) {
374                                                            unlink($f) || die "can't delete file $f: $!";
375    #                                               } else {
376    #                                                       rmtree($f) || die "can't delete dir $f: $!";
377                                                    }
378                                                    log_system("$cvs delete '$f'", "cvs delete of file $f failed");
379                                                    push @sub_commit, $f;
380                                            }
381                                            log_system("$cvs delete '$path'", "cvs delete of file $path failed");
382                                            cvs_commit($msg, @sub_commit, $path);
383                                            log_system("$cvs update -dP '$path'", "cvs update -dP $path failed");
384                                    } else {
385                                            warn "#### remove file: $path";
386                                            unlink($path) || die "can't delete $path: $!";
387                                            log_system("$cvs delete '$path'", "cvs delete of dir $path failed");
388                                    }
389                          } else {                          } else {
390                                  print "WARNING: $path is not present, skipping...\n";                                  print "WARNING: $path is not present, skipping...\n";
391                                  undef $path;                                  undef $path;
# Line 327  foreach my $e (@{$xml->{'logentry'}}) { Line 399  foreach my $e (@{$xml->{'logentry'}}) {
399    
400          }          }
401    
         my $msg = $e->{'msg'};  
         $msg =~ s/'/'\\''/g;    # quote "  
   
402          # now commit changes          # now commit changes
403          log_system("$cvs commit -m '$msg' '".join("' '",@commit)."'", "cvs commit of ".join(",",@commit)." failed");          cvs_commit($msg, @commit);
404    
405          commit_svnrev($rev);          commit_svnrev($rev);
406  }  }

Legend:
Removed from v.30  
changed lines
  Added in v.36

  ViewVC Help
Powered by ViewVC 1.1.26