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

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

  ViewVC Help
Powered by ViewVC 1.1.26