@matheusbsbs / matheus-bagliano / commits / 83936a29e2
Fork 0

git-svnimport.perl: copying directory from original SVN place

When copying whole directory, if source directory is not in already imported tree, try to get it from original SVN location. This happens when source directory is not matched by provided 'trunk' and/or 'tags/branches' templates or when it is not part of specified SVN sub-project. Signed-off-by: Sasha Khapyorsky <sashak@voltaire.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Sasha Khapyorsky committed Oct 8, 2006 at 23:31 UTC 83936a29e275bc0c04f60d3333e4951a9e16b1fc
1 file changed +54 -39
git-svnimport.perl
+54 -39
@@ -193,6 +193,13 @@ sub ignore {
193 }
194 }
195
196 +sub dir_list {
197 + my($self,$path,$rev) = @_;
198 + my ($dirents,undef,$properties)
199 + = $self->{'svn'}->get_dir($path,$rev,undef);
200 + return $dirents;
201 +}
202 +
203 package main;
204 use URI;
205
@@ -342,35 +349,16 @@ if ($opt_A) {
349
350 open BRANCHES,">>", "$git_dir/svn2git";
351
345 -sub node_kind($$$) {
346 - my ($branch, $path, $revision) = @_;
352 +sub node_kind($$) {
353 + my ($svnpath, $revision) = @_;
354 my $pool=SVN::Pool->new;
348 - my $kind = $svn->{'svn'}->check_path(revert_split_path($branch,$path),$revision,$pool);
355 + my $kind = $svn->{'svn'}->check_path($svnpath,$revision,$pool);
356 $pool->clear;
357 return $kind;
358 }
359
353 -sub revert_split_path($$) {
354 - my($branch,$path) = @_;
355 -
356 - my $svnpath;
357 - $path = "" if $path eq "/"; # this should not happen, but ...
358 - if($branch eq "/") {
359 - $svnpath = "$trunk_name/$path";
360 - } elsif($branch =~ m#^/#) {
361 - $svnpath = "$tag_name$branch/$path";
362 - } else {
363 - $svnpath = "$branch_name/$branch/$path";
364 - }
365 -
366 - $svnpath =~ s#/+$##;
367 - return $svnpath;
368 -}
369 -
360 sub get_file($$$) {
371 - my($rev,$branch,$path) = @_;
372 -
373 - my $svnpath = revert_split_path($branch,$path);
361 + my($svnpath,$rev,$path) = @_;
362
363 # now get it
364 my ($name,$mode);
@@ -413,10 +401,9 @@ sub get_file($$$) {
401 }
402
403 sub get_ignore($$$$$) {
416 - my($new,$old,$rev,$branch,$path) = @_;
404 + my($new,$old,$rev,$path,$svnpath) = @_;
405
406 return unless $opt_I;
419 - my $svnpath = revert_split_path($branch,$path);
407 my $name = $svn->ignore("$svnpath",$rev);
408 if ($path eq '/') {
409 $path = $opt_I;
@@ -435,7 +422,7 @@ sub get_ignore($$$$$) {
422 close $F;
423 unlink $name;
424 push(@$new,['0644',$sha,$path]);
438 - } else {
425 + } elsif (defined $old) {
426 push(@$old,$path);
427 }
428 }
@@ -480,6 +467,27 @@ sub branch_rev($$) {
467 return $therev;
468 }
469
470 +sub expand_svndir($$$);
471 +
472 +sub expand_svndir($$$)
473 +{
474 + my ($svnpath, $rev, $path) = @_;
475 + my @list;
476 + get_ignore(\@list, undef, $rev, $path, $svnpath);
477 + my $dirents = $svn->dir_list($svnpath, $rev);
478 + foreach my $p(keys %$dirents) {
479 + my $kind = node_kind($svnpath.'/'.$p, $rev);
480 + if ($kind eq $SVN::Node::file) {
481 + my $f = get_file($svnpath.'/'.$p, $rev, $path.'/'.$p);
482 + push(@list, $f) if $f;
483 + } elsif ($kind eq $SVN::Node::dir) {
484 + push(@list,
485 + expand_svndir($svnpath.'/'.$p, $rev, $path.'/'.$p));
486 + }
487 + }
488 + return @list;
489 +}
490 +
491 sub copy_path($$$$$$$$) {
492 # Somebody copied a whole subdirectory.
493 # We need to find the index entries from the old version which the
@@ -488,8 +496,11 @@ sub copy_path($$$$$$$$) {
496 my($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;
497
498 my($srcbranch,$srcpath) = split_path($rev,$oldpath);
491 - unless(defined $srcbranch) {
492 - print "Path not found when copying from $oldpath @ $rev\n";
499 + unless(defined $srcbranch && defined $srcpath) {
500 + print "Path not found when copying from $oldpath @ $rev.\n".
501 + "Will try to copy from original SVN location...\n"
502 + if $opt_v;
503 + push (@$new, expand_svndir($oldpath, $rev, $path));
504 return;
505 }
506 my $therev = branch_rev($srcbranch, $rev);
@@ -503,7 +514,7 @@ sub copy_path($$$$$$$$) {
514 }
515 print "$newrev:$newbranch:$path: copying from $srcbranch:$srcpath @ $rev\n" if $opt_v;
516 if ($node_kind eq $SVN::Node::dir) {
506 - $srcpath =~ s#/*$#/#;
517 + $srcpath =~ s#/*$#/#;
518 }
519
520 my $pid = open my $f,'-|';
@@ -582,10 +593,12 @@ sub commit {
593 if(defined $oldpath) {
594 my $p;
595 ($parent,$p) = split_path($revision,$oldpath);
585 - if($parent eq "/") {
586 - $parent = $opt_o;
587 - } else {
588 - $parent =~ s#^/##; # if it's a tag
596 + if(defined $parent) {
597 + if($parent eq "/") {
598 + $parent = $opt_o;
599 + } else {
600 + $parent =~ s#^/##; # if it's a tag
601 + }
602 }
603 } else {
604 $parent = undef;
@@ -651,9 +664,10 @@ sub commit {
664 push(@old,$path); # remove any old stuff
665 }
666 if(($action->[0] eq "A") || ($action->[0] eq "R")) {
654 - my $node_kind = node_kind($branch,$path,$revision);
667 + my $node_kind = node_kind($action->[3], $revision);
668 if ($node_kind eq $SVN::Node::file) {
656 - my $f = get_file($revision,$branch,$path);
669 + my $f = get_file($action->[3],
670 + $revision, $path);
671 if ($f) {
672 push(@new,$f) if $f;
673 } else {
@@ -668,19 +682,20 @@ sub commit {
682 \@new, \@parents);
683 } else {
684 get_ignore(\@new, \@old, $revision,
671 - $branch, $path);
685 + $path, $action->[3]);
686 }
687 }
688 } elsif ($action->[0] eq "D") {
689 push(@old,$path);
690 } elsif ($action->[0] eq "M") {
677 - my $node_kind = node_kind($branch,$path,$revision);
691 + my $node_kind = node_kind($action->[3], $revision);
692 if ($node_kind eq $SVN::Node::file) {
679 - my $f = get_file($revision,$branch,$path);
693 + my $f = get_file($action->[3],
694 + $revision, $path);
695 push(@new,$f) if $f;
696 } elsif ($node_kind eq $SVN::Node::dir) {
697 get_ignore(\@new, \@old, $revision,
683 - $branch,$path);
698 + $path, $action->[3]);
699 }
700 } else {
701 die "$revision: unknown action '".$action->[0]."' for $path\n";