/[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 7 by dpavlin, Tue Mar 9 22:35:55 2004 UTC revision 8 by dpavlin, Thu Mar 11 16:26:49 2004 UTC
# Line 14  use File::Temp qw/ tempdir /; Line 14  use File::Temp qw/ tempdir /;
14  use Data::Dumper;  use Data::Dumper;
15  use XML::Simple;  use XML::Simple;
16    
17  # get current user home directory  if (@ARGV < 2) {
18  my $HOME = $ENV{'HOME'} || die "can't get home directory!";          print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n";
19            exit 1;
20    }
21    
22    my ($SVNROOT,$CVSROOT, $CVSREP) = @ARGV;
23    
24  # cvsroot directory  if ($SVNROOT !~ m,^\w+:///*\w+,) {
25  my $CVSROOT=':pserver:dpavlin@cvs.tigris.org:/cvs';          print "ERROR: invalid svn root $SVNROOT\n";
26  # name of cvs repository to commit to          exit 1;
27  my $CVSREP="svn2cvs/src";  }
   
 $CVSROOT="$HOME/x/cvsroot";  
 $CVSREP="svn2cvs/src";  
   
 # svnroot directory  
 my $SVNROOT="file://$HOME/private/svn/svn2cvs";  
 # name of respository  
 my $SVNREP="trunk";  
   
 # webpac example  
 #$CVSROOT="$HOME/x/cvsroot";  
 #$CVSREP="webpac";  
 #$SVNROOT="file://$HOME/private/svn/webpac/";  
 #$SVNREP="trunk";  
28    
29  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );
30    
# Line 49  my $cvs="cvs -d $CVSROOT"; Line 39  my $cvs="cvs -d $CVSROOT";
39  sub log_system($$) {  sub log_system($$) {
40          my ($cmd,$errmsg) = @_;          my ($cmd,$errmsg) = @_;
41          print STDERR "## $cmd\n";          print STDERR "## $cmd\n";
42          system $cmd || die "$errmsg: $!";          system($cmd) == 0 || die "$errmsg: $!";
43  }  }
44    
45  #  #
# Line 78  sub commit_svnrev { Line 68  sub commit_svnrev {
68    
69  # ok, now do the checkout  # ok, now do the checkout
70    
71  log_system("$cvs -q checkout $CVSREP","cvs checkout failed");  log_system("$cvs -q checkout $CVSREP", "cvs checkout failed");
72    
73  chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!";  chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!";
74    
# Line 133  $rev++; Line 123  $rev++;
123  # case much about accuracy and completnes of logs there, this might  # case much about accuracy and completnes of logs there, this might
124  # be good. YMMV  # be good. YMMV
125  #  #
126  open(LOG, "svn log -r $rev:HEAD -v --xml $SVNROOT/$SVNREP |") || die "svn log for repository $SVNROOT/$SVNREP failed: $!";  open(LOG, "svn log -r $rev:HEAD -v --xml $SVNROOT |") || die "svn log for repository $SVNROOT failed: $!";
127  my $log;  my $log;
128  while(<LOG>) {  while(<LOG>) {
129          $log .= $_;          $log .= $_;
# Line 162  if (! $xml->{'logentry'}) { Line 152  if (! $xml->{'logentry'}) {
152  foreach my $e (@{$xml->{'logentry'}}) {  foreach my $e (@{$xml->{'logentry'}}) {
153          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'});
154          $rev = $e->{'revision'};          $rev = $e->{'revision'};
155          log_system("svn export --force -q -r $rev $SVNROOT/$SVNREP $TMPDIR/$CVSREP", "svn export of revision $rev failed");          log_system("svn export --force -q -r $rev $SVNROOT $TMPDIR/$CVSREP", "svn export of revision $rev failed");
156    
157            # deduce name of svn directory
158            my $SVNREP = "";
159            my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!";
160            my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!";
161            do {
162    print "## tmppath: $tmppath tmpsvn: $tmpsvn SVNREP: $SVNREP\n";
163                    if ($tmpsvn =~ s,(/\w+/*)$,,) {
164                            $SVNREP .= $1;
165                    } else {
166                            die "ERROR: can't deduce svn dir from $SVNROOT.\nUsing root of snv repository for current version instead of /trunk/ is not supported.\n";
167                    }
168            } until ($tmppath =~ m/^$SVNREP/);
169    
170            print "NOTICE: using $SVNREP as directory for svn\n";
171    
172          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});
173          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
# Line 172  foreach my $e (@{$xml->{'logentry'}}) { Line 177  foreach my $e (@{$xml->{'logentry'}}) {
177    
178                  # prepare path and message                  # prepare path and message
179                  my $file = $path;                  my $file = $path;
180                  $path =~ s,^/$SVNREP/*,, || die "BUG: can't strip SVNREP from path";                  $path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP from path";
181    
182                  if (! $path) {                  if (! $path) {
183                          print "NOTICE: skipped this operation. Probably trunk creation\n";                          print "NOTICE: skipped this operation. Probably trunk creation\n";
# Line 185  foreach my $e (@{$xml->{'logentry'}}) { Line 190  foreach my $e (@{$xml->{'logentry'}}) {
190                  if ($action =~ /M/) {                  if ($action =~ /M/) {
191                          print "svn2cvs: modify $path -- nop\n";                          print "svn2cvs: modify $path -- nop\n";
192                  } elsif ($action =~ /A/) {                  } elsif ($action =~ /A/) {
193                          log_system("$cvs add -m \"$msg\" $path", "cvs add of $path failed");                          if (-d $path) {
194                                    chdir($path) || die "can't cd into dir $path for import: $!";
195                                    log_system("$cvs import -d -m \"$msg\" $CVSREP/$path svn r$rev", "cvs import of $path failed");
196                                    chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!";
197                                    log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed");
198                                    chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!";
199                            } else {
200                                    log_system("$cvs add -m \"$msg\" $path", "cvs add of $path failed");
201                            }
202                  } elsif ($action =~ /D/) {                  } elsif ($action =~ /D/) {
203                          log_system("$cvs delete -m \"$msg\" $path", "cvs delete of $path failed");                          log_system("$cvs delete -m \"$msg\" $path", "cvs delete of $path failed");
204                  } else {                  } else {
# Line 199  foreach my $e (@{$xml->{'logentry'}}) { Line 212  foreach my $e (@{$xml->{'logentry'}}) {
212    
213          commit_svnrev($rev);          commit_svnrev($rev);
214  }  }
   
 __END__  
   
 svn export --force "$SVNROOT/$SVNREP" "$CVSREP"  
   
 cd dotfiles  
   
 for file in $(find -type f -not -path \*CVS\*); do  
         FILE=$(basename $file)  
         DIR=$(dirname $file)  
         if ! grep -q "^/$FILE/" $DIR/CVS/Entries ; then  
                 cvs add $file  
         fi  
 done  
   
 #cvs commit -m "Automatic commit from SVN"  
   
 #rm -rf $TMPDIR  
   
 echo "cvs left in $TMPDIR"  

Legend:
Removed from v.7  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26