/[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 1 by dpavlin, Tue Mar 9 20:58:34 2004 UTC revision 6 by dpavlin, Tue Mar 9 22:16:19 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  # ok, now do the checkout          die "commit_svnrev needs revision" if (! defined($rev));
   
 log_system("$cvs checkout $CVSREP","cvs checkout failed");  
62    
63  # check if svnrev exists          open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";
64            print SVNREV $rev;
65            close(SVNREV);
66    
67  if (! -e "$CVSREP/.svnrev") {          my $path=".svnrev";
         print <<_USAGE_;  
68    
69          Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file!          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    
         This file is used to commit changes to CVS repository with correct  
         logs from Subversion.  
78    
79          Please create .svnrec file with currect svn revision which  # ok, now do the checkout
         corresponds to version of checkouted tree and commit that file  
         to CVS repository, e.g.  
   
         echo 233 > .svnrev  
         cvs add .svnrev  
         cvs commit -m "subversion repository revision sync file" .svnrev  
80    
81  _USAGE_  log_system("$cvs -q checkout $CVSREP","cvs checkout failed");
         print "CVS Repository left in $TMPDIR/$CVSREP\n";  
         exit 1;  
 }  
82    
83    my $rev;
84    
85  open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";  # check if svnrev exists
86  my $rev = <SVNREV>;  if (! -e "$CVSREP/.svnrev") {
87  chomp($rev);          print <<_USAGE_;
 close(SVNREV);  
88    
89  print "Starting after revision $rev\n";  Your CVS repository doesn't have .svnrev file!
90    
91    This file is used to keep CVS repository and SubVersion in sync, so
92    that only newer changes will be commited.
93    
94  #  It's quote possible that this is first svn2cvs run for this repository.
95  # sub to commit .svn rev file later  If so, you will have to identify correct svn revision which
96  #  corresponds to current version of CVS repository that has just
97    been checkouted.
98    
99    If you migrated your cvs repository to svn using cvs2svn, this will be
100    last SubVersion revision. If this is initial run of conversion of
101    SubVersion repository to CVS, correct revision is 0.
102    
103  sub commit_svnrev($) {  _USAGE_
         my $rev = shift @_ || die "commit_svnrev needs revision";  
104    
105          open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!";          print "svn revision corresponding to CVS [abort]: ";
106          print SVNREV $rev;          my $in = <STDIN>;
107            chomp($in);
108            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            $rev = <SVNREV>;
118            chomp($rev);
119          close(SVNREV);          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: $!";  
120  }  }
121    
122    print "Starting after revision $rev\n";
123    $rev++;
124    
125    
126  #  #
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
# Line 111  while(<LOG>) { Line 137  while(<LOG>) {
137  }  }
138  close(LOG);  close(LOG);
139    
140  my $xml = XMLin($log, ForceArray => [ 'path' ]);  my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
141    
142    
143  =begin log_example  =begin log_example
# Line 125  ported r254 from hidra branch Line 151  ported r254 from hidra branch
151    
152  my $fmt = "\n" . "-" x 79 . "\nr%5s| %8s | %s\n\n%s\n";  my $fmt = "\n" . "-" x 79 . "\nr%5s| %8s | %s\n\n%s\n";
153    
154    if (! $xml->{'logentry'}) {
155            print "no newer log entries in SubVersion repostory. CVS is current\n";
156            exit 0;
157    }
158    
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.1  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26