{"thread":{"id":"5857","subject":"[PATCH] git-svnimport.perl: copying directory from original SVN place","startedAt":"2006-10-08T21:31:18Z","lastAt":"2006-10-20T00:31:30Z","messageCount":4,"participants":["Sasha Khapyorsky","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"28436","messageId":"20061008213118.GA1367@sashak.voltaire.com","threadId":"5857","inReplyTo":null,"subject":"[PATCH] git-svnimport.perl: copying directory from original SVN place","fromName":"Sasha Khapyorsky","fromEmail":"sashak@voltaire.com","sentAt":"2006-10-08T21:31:18Z","receivedAt":"2006-10-08T21:31:18Z","isPatch":true,"sender":{"key":"sashak@voltaire.com","avatar":null},"body":"\nWhen copying whole directory, if source directory is not in already\nimported tree, try to get it from original SVN location. This happens\nwhen source directory is not matched by provided 'trunk' and/or\n'tags/branches' templates or when it is not part of specified SVN\nsub-project.\n\nSigned-off-by: Sasha Khapyorsky <sashak@voltaire.com>\n---\n git-svnimport.perl |   93 ++++++++++++++++++++++++++++++----------------------\n 1 files changed, 54 insertions(+), 39 deletions(-)\n\ndiff --git a/git-svnimport.perl b/git-svnimport.perl\nindex 988514e..4ae0eec 100755\n--- a/git-svnimport.perl\n+++ b/git-svnimport.perl\n@@ -193,6 +193,13 @@ sub ignore {\n \t}\n }\n \n+sub dir_list {\n+\tmy($self,$path,$rev) = @_;\n+\tmy ($dirents,undef,$properties)\n+\t    = $self->{'svn'}->get_dir($path,$rev,undef);\n+\treturn $dirents;\n+}\n+\n package main;\n use URI;\n \n@@ -342,35 +349,16 @@ if ($opt_A) {\n \n open BRANCHES,\">>\", \"$git_dir/svn2git\";\n \n-sub node_kind($$$) {\n-\tmy ($branch, $path, $revision) = @_;\n+sub node_kind($$) {\n+\tmy ($svnpath, $revision) = @_;\n \tmy $pool=SVN::Pool->new;\n-\tmy $kind = $svn->{'svn'}->check_path(revert_split_path($branch,$path),$revision,$pool);\n+\tmy $kind = $svn->{'svn'}->check_path($svnpath,$revision,$pool);\n \t$pool->clear;\n \treturn $kind;\n }\n \n-sub revert_split_path($$) {\n-\tmy($branch,$path) = @_;\n-\n-\tmy $svnpath;\n-\t$path = \"\" if $path eq \"/\"; # this should not happen, but ...\n-\tif($branch eq \"/\") {\n-\t\t$svnpath = \"$trunk_name/$path\";\n-\t} elsif($branch =~ m#^/#) {\n-\t\t$svnpath = \"$tag_name$branch/$path\";\n-\t} else {\n-\t\t$svnpath = \"$branch_name/$branch/$path\";\n-\t}\n-\n-\t$svnpath =~ s#/+$##;\n-\treturn $svnpath;\n-}\n-\n sub get_file($$$) {\n-\tmy($rev,$branch,$path) = @_;\n-\n-\tmy $svnpath = revert_split_path($branch,$path);\n+\tmy($svnpath,$rev,$path) = @_;\n \n \t# now get it\n \tmy ($name,$mode);\n@@ -413,10 +401,9 @@ sub get_file($$$) {\n }\n \n sub get_ignore($$$$$) {\n-\tmy($new,$old,$rev,$branch,$path) = @_;\n+\tmy($new,$old,$rev,$path,$svnpath) = @_;\n \n \treturn unless $opt_I;\n-\tmy $svnpath = revert_split_path($branch,$path);\n \tmy $name = $svn->ignore(\"$svnpath\",$rev);\n \tif ($path eq '/') {\n \t\t$path = $opt_I;\n@@ -435,7 +422,7 @@ sub get_ignore($$$$$) {\n \t\tclose $F;\n \t\tunlink $name;\n \t\tpush(@$new,['0644',$sha,$path]);\n-\t} else {\n+\t} elsif (defined $old) {\n \t\tpush(@$old,$path);\n \t}\n }\n@@ -480,6 +467,27 @@ sub branch_rev($$) {\n \treturn $therev;\n }\n \n+sub expand_svndir($$$);\n+\n+sub expand_svndir($$$)\n+{\n+\tmy ($svnpath, $rev, $path) = @_;\n+\tmy @list;\n+\tget_ignore(\\@list, undef, $rev, $path, $svnpath);\n+\tmy $dirents = $svn->dir_list($svnpath, $rev);\n+\tforeach my $p(keys %$dirents) {\n+\t\tmy $kind = node_kind($svnpath.'/'.$p, $rev);\n+\t\tif ($kind eq $SVN::Node::file) {\n+\t\t\tmy $f = get_file($svnpath.'/'.$p, $rev, $path.'/'.$p);\n+\t\t\tpush(@list, $f) if $f;\n+\t\t} elsif ($kind eq $SVN::Node::dir) {\n+\t\t\tpush(@list,\n+\t\t\t     expand_svndir($svnpath.'/'.$p, $rev, $path.'/'.$p));\n+\t\t}\n+\t}\n+\treturn @list;\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@@ -488,8 +496,11 @@ sub copy_path($$$$$$$$) {\n \tmy($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;\n \n \tmy($srcbranch,$srcpath) = split_path($rev,$oldpath);\n-\tunless(defined $srcbranch) {\n-\t\tprint \"Path not found when copying from $oldpath @ $rev\\n\";\n+\tunless(defined $srcbranch && defined $srcpath) {\n+\t\tprint \"Path not found when copying from $oldpath @ $rev.\\n\".\n+\t\t\t\"Will try to copy from original SVN location...\\n\"\n+\t\t\tif $opt_v;\n+\t\tpush (@$new, expand_svndir($oldpath, $rev, $path));\n \t\treturn;\n \t}\n \tmy $therev = branch_rev($srcbranch, $rev);\n@@ -503,7 +514,7 @@ sub copy_path($$$$$$$$) {\n \t}\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\t$srcpath =~ s#/*$#/#;\n \t}\n \t\n \tmy $pid = open my $f,'-|';\n@@ -582,10 +593,12 @@ sub commit {\n \t\tif(defined $oldpath) {\n \t\t\tmy $p;\n \t\t\t($parent,$p) = split_path($revision,$oldpath);\n-\t\t\tif($parent eq \"/\") {\n-\t\t\t\t$parent = $opt_o;\n-\t\t\t} else {\n-\t\t\t\t$parent =~ s#^/##; # if it's a tag\n+\t\t\tif(defined $parent) {\n+\t\t\t\tif($parent eq \"/\") {\n+\t\t\t\t\t$parent = $opt_o;\n+\t\t\t\t} else {\n+\t\t\t\t\t$parent =~ s#^/##; # if it's a tag\n+\t\t\t\t}\n \t\t\t}\n \t\t} else {\n \t\t\t$parent = undef;\n@@ -651,9 +664,10 @@ #\t}\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\tmy $node_kind = node_kind($action->[3], $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\tmy $f = get_file($action->[3],\n+\t\t\t\t\t\t\t $revision, $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@@ -668,19 +682,20 @@ #\t}\n \t\t\t\t\t\t\t  \\@new, \\@parents);\n \t\t\t\t\t} else {\n \t\t\t\t\t\tget_ignore(\\@new, \\@old, $revision,\n-\t\t\t\t\t\t\t   $branch, $path);\n+\t\t\t\t\t\t\t   $path, $action->[3]);\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 $node_kind = node_kind($branch,$path,$revision);\n+\t\t\t\tmy $node_kind = node_kind($action->[3], $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\tmy $f = get_file($action->[3],\n+\t\t\t\t\t\t\t $revision, $path);\n \t\t\t\t\tpush(@new,$f) if $f;\n \t\t\t\t} elsif ($node_kind eq $SVN::Node::dir) {\n \t\t\t\t\tget_ignore(\\@new, \\@old, $revision,\n-\t\t\t\t\t\t   $branch,$path);\n+\t\t\t\t\t\t   $path, $action->[3]);\n \t\t\t\t}\n \t\t\t} else {\n \t\t\t\tdie \"$revision: unknown action '\".$action->[0].\"' for $path\\n\";\n-- \n1.4.2.3\n"},{"id":"29273","messageId":"20061020002219.GF24676@sashak.voltaire.com","threadId":"5857","inReplyTo":"20061008213118.GA1367@sashak.voltaire.com","subject":"Re: [PATCH] git-svnimport.perl: copying directory from original SVN place","fromName":"Sasha Khapyorsky","fromEmail":"sashak@voltaire.com","sentAt":"2006-10-20T00:22:19Z","receivedAt":"2006-10-20T00:22:19Z","isPatch":true,"sender":{"key":"sashak@voltaire.com","avatar":null},"body":"Hi guys,\n\nOn 23:31 Sun 08 Oct     , Sasha Khapyorsky wrote:\n> \n> When copying whole directory, if source directory is not in already\n> imported tree, try to get it from original SVN location. This happens\n> when source directory is not matched by provided 'trunk' and/or\n> 'tags/branches' templates or when it is not part of specified SVN\n> sub-project.\n\nAny news with it?\n\nSasha\n\n> \n> Signed-off-by: Sasha Khapyorsky <sashak@voltaire.com>\n> ---\n>  git-svnimport.perl |   93 ++++++++++++++++++++++++++++++----------------------\n>  1 files changed, 54 insertions(+), 39 deletions(-)\n> \n> diff --git a/git-svnimport.perl b/git-svnimport.perl\n> index 988514e..4ae0eec 100755\n> --- a/git-svnimport.perl\n> +++ b/git-svnimport.perl\n> @@ -193,6 +193,13 @@ sub ignore {\n>  \t}\n>  }\n>  \n> +sub dir_list {\n> +\tmy($self,$path,$rev) = @_;\n> +\tmy ($dirents,undef,$properties)\n> +\t    = $self->{'svn'}->get_dir($path,$rev,undef);\n> +\treturn $dirents;\n> +}\n> +\n>  package main;\n>  use URI;\n>  \n> @@ -342,35 +349,16 @@ if ($opt_A) {\n>  \n>  open BRANCHES,\">>\", \"$git_dir/svn2git\";\n>  \n> -sub node_kind($$$) {\n> -\tmy ($branch, $path, $revision) = @_;\n> +sub node_kind($$) {\n> +\tmy ($svnpath, $revision) = @_;\n>  \tmy $pool=SVN::Pool->new;\n> -\tmy $kind = $svn->{'svn'}->check_path(revert_split_path($branch,$path),$revision,$pool);\n> +\tmy $kind = $svn->{'svn'}->check_path($svnpath,$revision,$pool);\n>  \t$pool->clear;\n>  \treturn $kind;\n>  }\n>  \n> -sub revert_split_path($$) {\n> -\tmy($branch,$path) = @_;\n> -\n> -\tmy $svnpath;\n> -\t$path = \"\" if $path eq \"/\"; # this should not happen, but ...\n> -\tif($branch eq \"/\") {\n> -\t\t$svnpath = \"$trunk_name/$path\";\n> -\t} elsif($branch =~ m#^/#) {\n> -\t\t$svnpath = \"$tag_name$branch/$path\";\n> -\t} else {\n> -\t\t$svnpath = \"$branch_name/$branch/$path\";\n> -\t}\n> -\n> -\t$svnpath =~ s#/+$##;\n> -\treturn $svnpath;\n> -}\n> -\n>  sub get_file($$$) {\n> -\tmy($rev,$branch,$path) = @_;\n> -\n> -\tmy $svnpath = revert_split_path($branch,$path);\n> +\tmy($svnpath,$rev,$path) = @_;\n>  \n>  \t# now get it\n>  \tmy ($name,$mode);\n> @@ -413,10 +401,9 @@ sub get_file($$$) {\n>  }\n>  \n>  sub get_ignore($$$$$) {\n> -\tmy($new,$old,$rev,$branch,$path) = @_;\n> +\tmy($new,$old,$rev,$path,$svnpath) = @_;\n>  \n>  \treturn unless $opt_I;\n> -\tmy $svnpath = revert_split_path($branch,$path);\n>  \tmy $name = $svn->ignore(\"$svnpath\",$rev);\n>  \tif ($path eq '/') {\n>  \t\t$path = $opt_I;\n> @@ -435,7 +422,7 @@ sub get_ignore($$$$$) {\n>  \t\tclose $F;\n>  \t\tunlink $name;\n>  \t\tpush(@$new,['0644',$sha,$path]);\n> -\t} else {\n> +\t} elsif (defined $old) {\n>  \t\tpush(@$old,$path);\n>  \t}\n>  }\n> @@ -480,6 +467,27 @@ sub branch_rev($$) {\n>  \treturn $therev;\n>  }\n>  \n> +sub expand_svndir($$$);\n> +\n> +sub expand_svndir($$$)\n> +{\n> +\tmy ($svnpath, $rev, $path) = @_;\n> +\tmy @list;\n> +\tget_ignore(\\@list, undef, $rev, $path, $svnpath);\n> +\tmy $dirents = $svn->dir_list($svnpath, $rev);\n> +\tforeach my $p(keys %$dirents) {\n> +\t\tmy $kind = node_kind($svnpath.'/'.$p, $rev);\n> +\t\tif ($kind eq $SVN::Node::file) {\n> +\t\t\tmy $f = get_file($svnpath.'/'.$p, $rev, $path.'/'.$p);\n> +\t\t\tpush(@list, $f) if $f;\n> +\t\t} elsif ($kind eq $SVN::Node::dir) {\n> +\t\t\tpush(@list,\n> +\t\t\t     expand_svndir($svnpath.'/'.$p, $rev, $path.'/'.$p));\n> +\t\t}\n> +\t}\n> +\treturn @list;\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> @@ -488,8 +496,11 @@ sub copy_path($$$$$$$$) {\n>  \tmy($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;\n>  \n>  \tmy($srcbranch,$srcpath) = split_path($rev,$oldpath);\n> -\tunless(defined $srcbranch) {\n> -\t\tprint \"Path not found when copying from $oldpath @ $rev\\n\";\n> +\tunless(defined $srcbranch && defined $srcpath) {\n> +\t\tprint \"Path not found when copying from $oldpath @ $rev.\\n\".\n> +\t\t\t\"Will try to copy from original SVN location...\\n\"\n> +\t\t\tif $opt_v;\n> +\t\tpush (@$new, expand_svndir($oldpath, $rev, $path));\n>  \t\treturn;\n>  \t}\n>  \tmy $therev = branch_rev($srcbranch, $rev);\n> @@ -503,7 +514,7 @@ sub copy_path($$$$$$$$) {\n>  \t}\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\t$srcpath =~ s#/*$#/#;\n>  \t}\n>  \t\n>  \tmy $pid = open my $f,'-|';\n> @@ -582,10 +593,12 @@ sub commit {\n>  \t\tif(defined $oldpath) {\n>  \t\t\tmy $p;\n>  \t\t\t($parent,$p) = split_path($revision,$oldpath);\n> -\t\t\tif($parent eq \"/\") {\n> -\t\t\t\t$parent = $opt_o;\n> -\t\t\t} else {\n> -\t\t\t\t$parent =~ s#^/##; # if it's a tag\n> +\t\t\tif(defined $parent) {\n> +\t\t\t\tif($parent eq \"/\") {\n> +\t\t\t\t\t$parent = $opt_o;\n> +\t\t\t\t} else {\n> +\t\t\t\t\t$parent =~ s#^/##; # if it's a tag\n> +\t\t\t\t}\n>  \t\t\t}\n>  \t\t} else {\n>  \t\t\t$parent = undef;\n> @@ -651,9 +664,10 @@ #\t}\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\tmy $node_kind = node_kind($action->[3], $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\tmy $f = get_file($action->[3],\n> +\t\t\t\t\t\t\t $revision, $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> @@ -668,19 +682,20 @@ #\t}\n>  \t\t\t\t\t\t\t  \\@new, \\@parents);\n>  \t\t\t\t\t} else {\n>  \t\t\t\t\t\tget_ignore(\\@new, \\@old, $revision,\n> -\t\t\t\t\t\t\t   $branch, $path);\n> +\t\t\t\t\t\t\t   $path, $action->[3]);\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 $node_kind = node_kind($branch,$path,$revision);\n> +\t\t\t\tmy $node_kind = node_kind($action->[3], $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\tmy $f = get_file($action->[3],\n> +\t\t\t\t\t\t\t $revision, $path);\n>  \t\t\t\t\tpush(@new,$f) if $f;\n>  \t\t\t\t} elsif ($node_kind eq $SVN::Node::dir) {\n>  \t\t\t\t\tget_ignore(\\@new, \\@old, $revision,\n> -\t\t\t\t\t\t   $branch,$path);\n> +\t\t\t\t\t\t   $path, $action->[3]);\n>  \t\t\t\t}\n>  \t\t\t} else {\n>  \t\t\t\tdie \"$revision: unknown action '\".$action->[0].\"' for $path\\n\";\n> -- \n> 1.4.2.3\n> \n"},{"id":"29277","messageId":"7vmz7rrg1a.fsf@assigned-by-dhcp.cox.net","threadId":"5857","inReplyTo":"20061020002219.GF24676@sashak.voltaire.com","subject":"Re: [PATCH] git-svnimport.perl: copying directory from original SVN place","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-20T00:23:45Z","receivedAt":"2006-10-20T00:23:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sasha Khapyorsky <sashak@voltaire.com> writes:\n\n> Hi guys,\n>\n> On 23:31 Sun 08 Oct     , Sasha Khapyorsky wrote:\n>> \n>> When copying whole directory, if source directory is not in already\n>> imported tree, try to get it from original SVN location. This happens\n>> when source directory is not matched by provided 'trunk' and/or\n>> 'tags/branches' templates or when it is not part of specified SVN\n>> sub-project.\n>\n> Any news with it?\n\nI've pushed it out in \"master\" after 1.4.3, to see if anybody\ncares about git-svnimport would scream.  If we do not hear from\nanybody about breakage that would be a good sign, otherwise we\nwould get a fix so that is good as well ;-).\n"},{"id":"29278","messageId":"20061020003130.GG24676@sashak.voltaire.com","threadId":"5857","inReplyTo":"7vmz7rrg1a.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-svnimport.perl: copying directory from original SVN place","fromName":"Sasha Khapyorsky","fromEmail":"sashak@voltaire.com","sentAt":"2006-10-20T00:31:30Z","receivedAt":"2006-10-20T00:31:30Z","isPatch":true,"sender":{"key":"sashak@voltaire.com","avatar":null},"body":"On 17:23 Thu 19 Oct     , Junio C Hamano wrote:\n> Sasha Khapyorsky <sashak@voltaire.com> writes:\n> \n> > Hi guys,\n> >\n> > On 23:31 Sun 08 Oct     , Sasha Khapyorsky wrote:\n> >> \n> >> When copying whole directory, if source directory is not in already\n> >> imported tree, try to get it from original SVN location. This happens\n> >> when source directory is not matched by provided 'trunk' and/or\n> >> 'tags/branches' templates or when it is not part of specified SVN\n> >> sub-project.\n> >\n> > Any news with it?\n> \n> I've pushed it out in \"master\" after 1.4.3, to see if anybody\n> cares about git-svnimport would scream.  If we do not hear from\n> anybody about breakage that would be a good sign, otherwise we\n> would get a fix so that is good as well ;-).\n\nCool. Thanks.\n\nSasha\n"}]}