/[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 31 by dpavlin, Wed Sep 5 20:39:29 2007 UTC revision 35 by dpavlin, Fri Sep 7 16:39:42 2007 UTC
# Line 222  if (! $xml->{'logentry'}) { Line 222  if (! $xml->{'logentry'}) {
222          exit 0;          exit 0;
223  }  }
224    
225  # check if file exists in CVS/Entries  # my ($dir,$file) = dir_file($path);
226  sub in_entries($) {  sub dir_file($) {
227          my $path = shift;          my $path = shift;
228          if ($path !~ m,^(.*?/*)([^/]+)$,) {          if ($path !~ m,^(.*?/*)([^/]+)$,) {
229                  die "can't split '$path' to dir and file!";                  die "can't split '$path' to dir and file!";
# Line 232  sub in_entries($) { Line 232  sub in_entries($) {
232                  if ($d !~ m,/$, && $d ne "") {                  if ($d !~ m,/$, && $d ne "") {
233                          $d .= "/";                          $d .= "/";
234                  }                  }
235                  open(E, $d."CVS/Entries") || return 0;                  return ($d,$f);
236                  while(<E>) {          }
237                          return(1) if (m,^/$f/,);  }
238    
239    # return all files in CVS/Entries
240    sub entries($) {
241            my $dir = shift;
242            die "entries expects directory argument!" unless -d $dir;
243            my @entries;
244            open(my $fh, "$dir/CVS/Entries") || return 0;
245            while(<$fh>) {
246                    if ( m{^D/([^/]+)}, ) {
247                            my $sub_dir = $1;
248                            warn "#### entries recurse into: $dir/$sub_dir";
249                            push @entries, map { "$sub_dir/$_" } entries("$dir/$sub_dir");
250                            push @entries, $sub_dir;
251                    } elsif ( m{^/([^/]+)/} ) {
252                            push @entries, $1;
253                    } elsif ( ! m{^D$} ) {
254                            die "can't decode entries line: $_";
255                  }                  }
                 close(E);  
                 return 0;  
256          }          }
257            close($fh);
258            warn "#### entries($dir) => ",join("|",@entries);
259            return @entries;
260    }
261    
262    # check if file exists in CVS/Entries
263    sub in_entries($) {
264            my $path = shift;
265            my ($dir,$file) = dir_file($path);
266            open(E, "$dir/CVS/Entries") || return 0;
267            while(<E>) {
268                    return(1) if (m,^/$file/,);
269            }
270            close(E);
271            return 0;
272  }  }
273    
274  cd_tmp;  cd_tmp;
# Line 254  foreach my $e (@{$xml->{'logentry'}}) { Line 284  foreach my $e (@{$xml->{'logentry'}}) {
284          my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!";          my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!";
285          my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!";          my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!";
286          do {          do {
287                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {                  if ($tmpsvn =~ s#(/[^/]+)/*$##) {       # vim fix
288                          $SVNREP = $1 . $SVNREP;                          $SVNREP = $1 . $SVNREP;
289                  } elsif ($e->{'paths'}->{'path'}->[0]->{'copyfrom-path'}) {                  } elsif ($e->{'paths'}->{'path'}->[0]->{'copyfrom-path'}) {
290                          print "NOTICE: copyfrom outside synced repository ignored - skipping\n";                          print "NOTICE: copyfrom outside synced repository ignored - skipping\n";
# Line 270  foreach my $e (@{$xml->{'logentry'}}) { Line 300  foreach my $e (@{$xml->{'logentry'}}) {
300          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});          printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'});
301          my @commit;          my @commit;
302    
303            my $msg = $e->{'msg'};
304            $msg =~ s/'/'\\''/g;    # quote "
305    
306            sub cvs_commit {
307                    my $msg = shift || die "no msg?";
308                    if ( ! @_ ) {
309                            warn "commit ignored, no files\n";
310                            return;
311                    }
312                    log_system("$cvs commit -m '$msg' '".join("' '",@_)."'", "cvs commit of ".join(",",@_)." failed");
313            }
314    
315          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
316                  my ($action,$path) = ($p->{'action'},$p->{'content'});                  my ($action,$path) = ($p->{'action'},$p->{'content'});
317    
# Line 318  foreach my $e (@{$xml->{'logentry'}}) { Line 360  foreach my $e (@{$xml->{'logentry'}}) {
360                          add_path($path);                          add_path($path);
361                  } elsif ($action =~ /D/) {                  } elsif ($action =~ /D/) {
362                          if (-e $path) {                          if (-e $path) {
363                                  unlink $path || die "can't delete $path: $!";                                  if ( -d $path ) {
364                                  log_system("$cvs delete '$path'", "cvs delete of $path failed");                                          warn "#### remove directory: $path";
365                                            my @sub_commit;
366                                            foreach my $f ( entries($path) ) {
367                                                    $f = "$path/$f";
368                                            if ( -f $f ) {
369                                                            unlink($f) || die "can't delete file $f: $!";
370    #                                               } else {
371    #                                                       rmtree($f) || die "can't delete dir $f: $!";
372                                                    }
373                                                    log_system("$cvs delete '$f'", "cvs delete of file $f failed");
374                                                    push @sub_commit, $f;
375                                            }
376                                            log_system("$cvs delete '$path'", "cvs delete of file $path failed");
377                                            cvs_commit($msg, @sub_commit, $path);
378                                            log_system("$cvs update -dP '$path'", "cvs update -dP $path failed");
379                                    } else {
380                                            warn "#### remove file: $path";
381                                            unlink($path) || die "can't delete $path: $!";
382                                            log_system("$cvs delete '$path'", "cvs delete of dir $path failed");
383                                    }
384                          } else {                          } else {
385                                  print "WARNING: $path is not present, skipping...\n";                                  print "WARNING: $path is not present, skipping...\n";
386                                  undef $path;                                  undef $path;
# Line 333  foreach my $e (@{$xml->{'logentry'}}) { Line 394  foreach my $e (@{$xml->{'logentry'}}) {
394    
395          }          }
396    
         my $msg = $e->{'msg'};  
         $msg =~ s/'/'\\''/g;    # quote "  
   
397          # now commit changes          # now commit changes
398          log_system("$cvs commit -m '$msg' '".join("' '",@commit)."'", "cvs commit of ".join(",",@commit)." failed");          cvs_commit($msg, @commit);
399    
400          commit_svnrev($rev);          commit_svnrev($rev);
401  }  }

Legend:
Removed from v.31  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26