/[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 21 by dpavlin, Fri Jul 1 19:07:10 2005 UTC revision 27 by dpavlin, Thu Aug 16 15:27:09 2007 UTC
# Line 17  use File::Path; Line 17  use File::Path;
17  use Data::Dumper;  use Data::Dumper;
18  use XML::Simple;  use XML::Simple;
19    
20    # do we want to sync just part of repository?
21    my $partial_import = 1;
22    
23  if (@ARGV < 2) {  if (@ARGV < 2) {
24          print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n";          print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n";
25          exit 1;          exit 1;
# Line 34  $SIG{__DIE__} = sub { chdir("/tmp"); die Line 37  $SIG{__DIE__} = sub { chdir("/tmp"); die
37    
38  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );
39    
40  chdir($TMPDIR) || die "can't cd to $TMPDIR: $!";  sub cd_tmp {
41            chdir($TMPDIR) || die "can't cd to $TMPDIR: $!";
42    }
43    
44    sub cd_rep {
45            chdir("$TMPDIR/$CVSREP") || die "can't cd to $TMPDIR/$CVSREP: $!";
46    }
47    
48    print "## using TMPDIR $TMPDIR\n";
49    
50  # cvs command with root  # cvs command with root
51  my $cvs="cvs -d $CVSROOT";  my $cvs="cvs -d $CVSROOT";
52    
53    # current revision in CVS
54    my $rev;
55    
56  #  #
57  # sub to do logging and system calls  # sub to do logging and system calls
58  #  #
# Line 72  sub commit_svnrev { Line 86  sub commit_svnrev {
86          }          }
87  }  }
88    
89  # current revision in CVS  sub add_dir($$) {
90  my $rev;          my ($path,$msg) = @_;
91            print "# add_dir($path)\n";
92            die "add_dir($path) is not directory" unless (-d $path);
93    
94            my $curr_dir;
95    
96            foreach my $d (split(m#/#, $path)) {
97                    $curr_dir .= ( $curr_dir ? '/' : '') . $d;
98    
99                    next if in_entries($curr_dir);
100                    next if (-e "$curr_dir/CVS");
101    
102                    log_system("$cvs add $curr_dir", "cvs add of $curr_dir failed");
103            }
104    }
105    
106  # ok, now do the checkout  # ok, now do the checkout
107  eval {  eval {
108            cd_tmp;
109          log_system("$cvs -q checkout $CVSREP", "cvs checkout failed");          log_system("$cvs -q checkout $CVSREP", "cvs checkout failed");
110  };  };
111    
# Line 92  _NEW_REP_ Line 121  _NEW_REP_
121    
122          print "start import of new module [yes]: ";          print "start import of new module [yes]: ";
123          my $in = <STDIN>;          my $in = <STDIN>;
124            cd_tmp;
125          mkdir($CVSREP) || die "can't create $CVSREP: $!";          mkdir($CVSREP) || die "can't create $CVSREP: $!";
126            cd_rep;
         chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!";  
127    
128          open(SVNREV,"> .svnrev") || die "can't open $CVSREP/.svnrev: $!";          open(SVNREV,"> .svnrev") || die "can't open $CVSREP/.svnrev: $!";
129          print SVNREV "0";          print SVNREV "0";
# Line 103  _NEW_REP_ Line 132  _NEW_REP_
132          $rev = 0;          $rev = 0;
133    
134          # create new module          # create new module
135          log_system("$cvs import -m 'new CVS module' $CVSREP svn2cvs r0", "can't import new module into $CVSREP");          cd_rep;
136            log_system("$cvs import -d -m 'new CVS module' $CVSREP svn r$rev", "import of new repository");
137          unlink ".svnrev" || die "can't remove .svnrev: $!";          cd_tmp;
138          chdir($TMPDIR) || die "can't cd to $TMPDIR: $!";          rmtree($CVSREP) || die "can't remove $CVSREP";
139          rmdir $CVSREP || die "can't remove $CVSREP: $!";          log_system("$cvs -q checkout $CVSREP", "cvs checkout failed");
140            cd_rep;
         # and get new changes it  
         log_system("$cvs -q update -d $CVSREP", "cvs update -d failed");  
   
         chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!";  
141    
142  } else {  } else {
   
143          # import into existing module directory in CVS          # import into existing module directory in CVS
144    
145          chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!";          cd_rep;
   
   
146          # check if svnrev exists          # check if svnrev exists
147          if (! -e ".svnrev") {          if (! -e ".svnrev") {
148                  print <<_USAGE_;                  print <<_USAGE_;
# Line 219  sub in_entries($) { Line 241  sub in_entries($) {
241          }          }
242  }  }
243    
244  chdir("$TMPDIR/$CVSREP") || die "can't cd to $TMPDIR/$CVSREP: $!";  cd_tmp;
245    cd_rep;
246    
247  foreach my $e (@{$xml->{'logentry'}}) {  foreach my $e (@{$xml->{'logentry'}}) {
248          die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'});          die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'});
# Line 233  foreach my $e (@{$xml->{'logentry'}}) { Line 256  foreach my $e (@{$xml->{'logentry'}}) {
256          do {          do {
257                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {
258                          $SVNREP = $1 . $SVNREP;                          $SVNREP = $1 . $SVNREP;
259                    } elsif ($e->{'paths'}->{'path'}->[0]->{'copyfrom-path'}) {
260                            print "NOTICE: copyfrom outside synced repository ignored - skipping\n";
261                            next;
262                  } else {                  } else {
263                          print "NOTICE: can't deduce svn dir from $SVNROOT - skipping\n";                          print "NOTICE: can't deduce svn dir from $SVNROOT - skipping\n";
264                          next;                          next;
# Line 247  foreach my $e (@{$xml->{'logentry'}}) { Line 273  foreach my $e (@{$xml->{'logentry'}}) {
273          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
274                  my ($action,$path) = ($p->{'action'},$p->{'content'});                  my ($action,$path) = ($p->{'action'},$p->{'content'});
275    
276                    next if ($path =~ m#/\.svnrev$#);
277    
278                  print "svn2cvs: $action $path\n";                  print "svn2cvs: $action $path\n";
279    
280                  # prepare path and message                  # prepare path and message
281                  my $file = $path;                  my $file = $path;
282                  $path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP '$SVNREP' from path";                  if ( $path !~ s#^\Q$SVNREP\E/*## ) {
283                            print "NOTICE: skipping '$path' which isn't under repository root '$SVNREP'\n";
284                            die unless $partial_import;
285                            next;
286                    }
287    
288                  if (! $path) {                  if (! $path) {
289                          print "NOTICE: skipped this operation. Probably trunk creation\n";                          print "NOTICE: skipped this operation. Probably trunk creation\n";
# Line 265  foreach my $e (@{$xml->{'logentry'}}) { Line 297  foreach my $e (@{$xml->{'logentry'}}) {
297                          print "svn2cvs: modify $path -- nop\n";                          print "svn2cvs: modify $path -- nop\n";
298                  } elsif ($action =~ /A/) {                  } elsif ($action =~ /A/) {
299                          if (-d $path) {                          if (-d $path) {
300                                  chdir($path) || die "can't cd into dir $path for import: $!";                                  add_dir($path, $msg);
                                 log_system("$cvs import -d -m '$msg' $CVSREP/$path svn r$rev", "cvs import of $path failed");  
                                 chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!";  
                                 if (-d "$CVSREP/$path") {  
                                         rmtree "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!";  
                                 } else {  
                                         unlink "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!";  
                                 }  
                                 log_system("$cvs update -d $CVSREP", "cvs update -d of imported dir $path failed");  
                                 chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!";  
301                          } elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") {                          } elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") {
302                                  my $dir = $1;                                  my $dir = $1;
303                                  in_entries($dir) || log_system("$cvs add $dir", "cvs add of dir $dir failed");                                  in_entries($dir) || add_dir($dir, $msg);
304                                  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");
305                          } else {                          } else {
306                                  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");
307                          }                          }
308                  } elsif ($action =~ /D/) {                  } elsif ($action =~ /D/) {
309                          unlink $path || die "can't delete $path: $!";                          if (-e $path) {
310                          log_system("$cvs delete $path", "cvs delete of $path failed");                                  unlink $path || die "can't delete $path: $!";
311                                    log_system("$cvs delete $path", "cvs delete of $path failed");
312                            } else {
313                                    print "WARNING: $path is not present, skipping...\n";
314                                    undef $path;
315                            }
316                  } else {                  } else {
317                          print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n";                          print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n";
318                  }                  }
319    
320                  # save commits for later                  # save commits for later
321                  push @commit, $path;                  push @commit, $path if ($path);
322    
323          }          }
324    
# Line 427  Use C<update -d> instead of checkout aft Line 455  Use C<update -d> instead of checkout aft
455  Added fixes by Paul Egan <paulegan@mail.com> for XMLin and fixing working  Added fixes by Paul Egan <paulegan@mail.com> for XMLin and fixing working
456  directory.  directory.
457    
458    =item r22
459    
460    Rewritten import from revision 0 to empty repository, better importing
461    of deep directory structures, initial support for recovery from partial
462    commit.
463    
464  =back  =back
465    

Legend:
Removed from v.21  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26