{"thread":{"id":"2326","subject":"[PATCH 4/7] copy_dir becomes copy_path and handles bothe files and directory","startedAt":"2005-11-02T21:51:57Z","lastAt":"2005-11-02T21:51:57Z","messageCount":1,"participants":["Yaacov Akiba Slama"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"11041","messageId":"E1EXQWT-00050G-UK@localhost.localdomain","threadId":"2326","inReplyTo":null,"subject":"[PATCH 4/7] copy_dir becomes copy_path and handles bothe files and directory","fromName":"Yaacov Akiba Slama","fromEmail":"ya@slamail.org","sentAt":"2005-11-02T21:51:57Z","receivedAt":"2005-11-02T21:51:57Z","isPatch":true,"sender":{"key":"ya@slamail.org","avatar":null},"body":"The A (Add) and R (Replace) actions handling are unified.\n\nSigned-off-by: Yaacov Akiba Slama <ya@slamail.org>\n\n---\n\n git-svnimport.perl |   90 +++++++++++++++++++++++++++++++---------------------\n 1 files changed, 53 insertions(+), 37 deletions(-)\n\napplies-to: 33a1ca1ccca482b3c467ad4ad10af877b59011f3\n0cab115306192e78516588e05045220f96106903\ndiff --git a/git-svnimport.perl b/git-svnimport.perl\nindex ea5bbdb..9cee629 100755\n--- a/git-svnimport.perl\n+++ b/git-svnimport.perl\n@@ -348,21 +348,42 @@ sub split_path($$) {\n \treturn ($branch,$path);\n }\n \n-sub copy_subdir($$$$$$) {\n+sub branch_rev($$) {\n+\n+\tmy ($srcbranch,$uptorev) = @_;\n+\n+\tmy $bbranches = $branches{$srcbranch};\n+\tmy @revs = reverse sort { ($a eq 'LAST' ? 0 : $a) <=> ($b eq 'LAST' ? 0 : $b) } keys %$bbranches;\n+\tmy $therev;\n+\tforeach my $arev(@revs) {\n+\t\tnext if  ($arev eq 'LAST');\n+\t\tif ($arev <= $uptorev) {\n+\t\t\t$therev = $arev;\n+\t\t\tlast;\n+\t\t}\n+\t}\n+\treturn $therev;\n+}\n+\n+sub copy_path($$$$$$$) {\n \t# Somebody copied a whole subdirectory.\n \t# We need to find the index entries from the old version which the\n \t# SVN log entry points to, and add them to the new place.\n \n-\tmy($newrev,$newbranch,$path,$oldpath,$rev,$new) = @_;\n-\tmy($branch,$srcpath) = split_path($rev,$oldpath);\n+\tmy($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new) = @_;\n \n-\tmy $gitrev = $branches{$branch}{$rev};\n+\tmy($srcbranch,$srcpath) = split_path($rev,$oldpath);\n+\tmy $therev = branch_rev($srcbranch, $rev);\n+\tmy $gitrev = $branches{$srcbranch}{$therev};\n \tunless($gitrev) {\n \t\tprint STDERR \"$newrev:$newbranch: could not find $oldpath \\@ $rev\\n\";\n \t\treturn;\n \t}\n-\tprint \"$newrev:$newbranch:$path: copying from $branch:$srcpath @ $rev\\n\" if $opt_v;\n-\t$srcpath =~ s#/*$#/#;\n+\tprint \"$newrev:$newbranch:$path: copying from $srcbranch:$srcpath @ $rev\\n\" if $opt_v;\n+\tif ($node_kind eq $SVN::Node::dir) {\n+\t\t\t$srcpath =~ s#/*$#/#;\n+\t}\n+\t\n \topen my $f,\"-|\",\"git-ls-tree\",\"-r\",\"-z\",$gitrev,$srcpath;\n \tlocal $/ = \"\\0\";\n \twhile(<$f>) {\n@@ -370,9 +391,12 @@ sub copy_subdir($$$$$$) {\n \t\tmy($m,$p) = split(/\\t/,$_,2);\n \t\tmy($mode,$type,$sha1) = split(/ /,$m);\n \t\tnext if $type ne \"blob\";\n-\t\t$p = substr($p,length($srcpath)-1);\n-\t\tprint \"... found $path$p ...\\n\" if $opt_v;\n-\t\tpush(@$new,[$mode,$sha1,$path.$p]);\n+\t\tif ($node_kind eq $SVN::Node::dir) {\n+\t\t\t$p = $path . substr($p,length($srcpath)-1);\n+\t\t} else {\n+\t\t\t$p = $path;\n+\t\t}\n+\t\tpush(@$new,[$mode,$sha1,$p]);\t\n \t}\n \tclose($f) or\n \t\tprint STDERR \"$newrev:$newbranch: could not list files in $oldpath \\@ $rev\\n\";\n@@ -476,39 +500,31 @@ sub commit {\n \t\tforeach my $path(@paths) {\n \t\t\tmy $action = $changed_paths->{$path};\n \n-\t\t\tif ($action->[0] eq \"A\") {\n-\t\t\t\tmy $f = get_file($revision,$branch,$path);\n-\t\t\t\tif($f) {\n-\t\t\t\t\tpush(@new,$f) if $f;\n-\t\t\t\t} elsif($action->[1]) {\n-\t\t\t\t\tcopy_subdir($revision,$branch,$path,$action->[1],$action->[2],\\@new);\n-\t\t\t\t} else {\n-\t\t\t\t\tmy $opath = $action->[3];\n-\t\t\t\t\tprint STDERR \"$revision: $branch: could not fetch '$opath'\\n\";\n+\t\t\tif ($action->[0] eq \"R\") {\n+\t\t\t\t# refer to a file/tree in an earlier commit\n+\t\t\t\tpush(@old,$path); # remove any old stuff\n+\t\t\t}\n+\t\t\tif(($action->[0] eq \"A\") || ($action->[0] eq \"R\")) {\n+\t\t\t\tmy $node_kind = node_kind($branch,$path,$revision);\n+\t\t\t\tif($action->[1]) {\n+\t\t\t\t\tcopy_path($revision,$branch,$path,$action->[1],$action->[2],$node_kind,\\@new);\n+\t\t\t\t} elsif ($node_kind eq $SVN::Node::file) {\n+\t\t\t\t\tmy $f = get_file($revision,$branch,$path);\n+\t\t\t\t\tif ($f) {\n+\t\t\t\t\t\tpush(@new,$f) if $f;\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\tmy $opath = $action->[3];\n+\t\t\t\t\t\tprint STDERR \"$revision: $branch: could not fetch '$opath'\\n\";\n+\t\t\t\t\t}\n \t\t\t\t}\n \t\t\t} elsif ($action->[0] eq \"D\") {\n \t\t\t\tpush(@old,$path);\n \t\t\t} elsif ($action->[0] eq \"M\") {\n-\t\t\t\tmy $f = get_file($revision,$branch,$path);\n-\t\t\t\tpush(@new,$f) if $f;\n-\t\t\t} elsif ($action->[0] eq \"R\") {\n-\t\t\t\t# refer to a file/tree in an earlier commit\n-\t\t\t\tpush(@old,$path); # remove any old stuff\n-\n-\t\t\t\t# ... and add any new stuff\n-\t\t\t\tmy($b,$srcpath) = split_path($revision,$action->[1]);\n-\t\t\t\t$srcpath =~ s#/*$#/#;\n-\t\t\t\topen my $F,\"-|\",\"git-ls-tree\",\"-r\",\"-z\", $branches{$b}{$action->[2]}, $srcpath;\n-\t\t\t\tlocal $/ = \"\\0\";\n-\t\t\t\twhile(<$F>) {\n-\t\t\t\t\tchomp;\n-\t\t\t\t\tmy($m,$p) = split(/\\t/,$_,2);\n-\t\t\t\t\tmy($mode,$type,$sha1) = split(/ /,$m);\n-\t\t\t\t\tnext if $type ne \"blob\";\n-\t\t\t\t\t$p = substr($p,length($srcpath)-1);\n-\t\t\t\t\tpush(@new,[$mode,$sha1,$path.$p]);\n+\t\t\t\tmy $node_kind = node_kind($branch,$path,$revision);\n+\t\t\t\tif ($node_kind eq $SVN::Node::file) {\n+\t\t\t\t\tmy $f = get_file($revision,$branch,$path);\n+\t\t\t\t\tpush(@new,$f) if $f;\n \t\t\t\t}\n-\t\t\t\tclose($F);\n \t\t\t} else {\n \t\t\t\tdie \"$revision: unknown action '\".$action->[0].\"' for $path\\n\";\n \t\t\t}\n---\n0.99.9.GIT\n"}]}