/[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 2 by dpavlin, Tue Mar 9 21:02:42 2004 UTC revision 5 by dpavlin, Tue Mar 9 22:04:14 2004 UTC
# Line 18  use XML::Simple; Line 18  use XML::Simple;
18  my $HOME = $ENV{'HOME'} || die "can't get home directory!";  my $HOME = $ENV{'HOME'} || die "can't get home directory!";
19    
20  # cvsroot directory  # cvsroot directory
21  my $CVSROOT="$HOME/x/cvsroot";  #my $CVSROOT="$HOME/x/cvsroot";
22    my $CVSROOT=':pserver:dpavlin@cvs.tigris.org:/cvs';
23  # name of cvs repository to commit to  # name of cvs repository to commit to
24  my $CVSREP="webpac";  my $CVSREP="svn2cvs/src";
25    
26  # svnroot directory  # svnroot directory
27  my $SVNROOT="file://$HOME/private/svn/webpac/";  my $SVNROOT="file://$HOME/private/svn/svn2cvs";
28  # name of respository  # name of respository
29  my $SVNREP="trunk";  my $SVNREP="trunk";
30    
31    # webpac example
32    #$CVSROOT="$HOME/x/cvsroot";
33    #$CVSREP="webpac";
34    #$SVNROOT="file://$HOME/private/svn/webpac/";
35    #$SVNREP="trunk";
36    
37  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );  my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 );
38    
39  chdir($TMPDIR) || die "can't cd to $TMPDIR: $!";  chdir($TMPDIR) || die "can't cd to $TMPDIR: $!";
# Line 34  chdir($TMPDIR) || die "can't cd to $TMPD Line 41  chdir($TMPDIR) || die "can't cd to $TMPD
41  # cvs command with root  # cvs command with root
42  my $cvs="cvs -d $CVSROOT";  my $cvs="cvs -d $CVSROOT";
43    
44    
45  #  #
46  # sub to do logging and system calls  # sub to do logging and system calls
47  #  #
# Line 43  sub log_system($$) { Line 51  sub log_system($$) {
51          system $cmd || die "$errmsg: $!";          system $cmd || die "$errmsg: $!";
52  }  }
53    
54    #
55    # sub to commit .svn rev file later
56    #
57    sub commit_svnrev {
58            my $rev = shift @_;
59            my $add_new = shift @_;
60    
61            die "commit_svnrev needs revision" if (! defined($rev));
62    
63            open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";
64            print SVNREV $rev;
65            close(SVNREV);
66    
67            my $path=".svnrev";
68    
69            if ($add_new) {
70                    system "$cvs add $CVSREP/$path" || die "cvs add of $path failed: $!";
71            } else {
72                    my $msg="subversion revision $rev commited to CVS";
73                    print "$msg\n";
74                    system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!";
75            }
76    }
77    
78    
79  # ok, now do the checkout  # ok, now do the checkout
80    
81  log_system("$cvs checkout $CVSREP","cvs checkout failed");  log_system("$cvs -q checkout $CVSREP","cvs checkout failed");
82    
83  # check if svnrev exists  my $rev;
84    
85    # check if svnrev exists
86  if (! -e "$CVSREP/.svnrev") {  if (! -e "$CVSREP/.svnrev") {
87          print <<_USAGE_;          print <<_USAGE_;
88    
89          Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file!  Your CVS repository doesn't have .svnrev file!
90    
91          This file is used to commit changes to CVS repository with correct  This file is used to keep CVS repository and SubVersion in sync, so
92          logs from Subversion.  that only newer changes will be commited.
93    
94          Please create .svnrec file with currect svn revision which  It's quote possible that this is first svn2cvs run for this repository.
95          corresponds to version of checkouted tree and commit that file  If so, you will have to identify correct svn revision which
96          to CVS repository, e.g.  corresponds to current version of CVS repository that has just
97    been checkouted.
98          echo 233 > .svnrev  
99          cvs add .svnrev  If you migrated your cvs repository to svn using cvs2svn, this will be
100          cvs commit -m "subversion repository revision sync file" .svnrev  last SubVersion revision. If this is initial run of conversion of
101    SubVersion repository to CVS, correct revision is 0.
102    
103  _USAGE_  _USAGE_
         print "CVS Repository left in $TMPDIR/$CVSREP\n";  
         exit 1;  
 }  
   
104    
105  open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";          print "svn revision corresponding to CVS [abort]: ";
106  my $rev = <SVNREV>;          my $in = <STDIN>;
107  chomp($rev);          chomp($in);
108  close(SVNREV);          if ($in !~ /^\d+$/) {
109                    print "Aborting: revision not a number\n";
110                    exit 1;
111            } else {
112                    $rev = $in;
113                    commit_svnrev($rev,1);  # create new
114            }
115    } else {
116            open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";
117            my $rev = <SVNREV>;
118            chomp($rev);
119            close(SVNREV);
120    }
121    
122  print "Starting after revision $rev\n";  print "Starting after revision $rev\n";
123  $rev++;  $rev++;
124    
125    
126  #  #
 # sub to commit .svn rev file later  
 #  
   
 sub commit_svnrev($) {  
         my $rev = shift @_ || die "commit_svnrev needs revision";  
   
         open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";  
         print SVNREV $rev;  
         close(SVNREV);  
   
         my $msg="subversion revision $rev commited to CVS";  
         my $path=".svnrev";  
         print "$msg\n";  
         system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!";  
 }  
   
 #  
127  # FIXME!! HEAD should really be next verison and loop because this way we  # FIXME!! HEAD should really be next verison and loop because this way we
128  # loose multiple edits of same file and corresponding messages. On the  # loose multiple edits of same file and corresponding messages. On the
129  # other hand, if you want to compress your traffic to CVS server and don't  # other hand, if you want to compress your traffic to CVS server and don't
# Line 131  if (! $xml->{'logentry'}) { Line 156  if (! $xml->{'logentry'}) {
156          exit 0;          exit 0;
157  }  }
158    
 print Dumper($xml);  
   
159  foreach my $e (@{$xml->{'logentry'}}) {  foreach my $e (@{$xml->{'logentry'}}) {
160          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'});
161          $rev = $e->{'revision'};          $rev = $e->{'revision'};

Legend:
Removed from v.2  
changed lines
  Added in v.5

  ViewVC Help
Powered by ViewVC 1.1.26