GIT 0.99.9j aka 1.0rc3
[git.git] / git-svnimport.perl
index cb9afb9..45d77c5 100755 (executable)
@@ -216,7 +216,11 @@ unless(-d $git_dir) {
        -f "$git_dir/svn2git"
                or die "'$git_dir/svn2git' does not exist.\n".
                       "You need that file for incremental imports.\n";
-       $last_branch = basename(readlink("$git_dir/HEAD"));
+       open(F, "git-symbolic-ref HEAD |") or
+               die "Cannot run git-symbolic-ref: $!\n";
+       chomp ($last_branch = <F>);
+       $last_branch = basename($last_branch);
+       close(F);
        unless($last_branch) {
                warn "Cannot read the last branch name: $! -- assuming 'master'\n";
                $last_branch = "master";
@@ -280,7 +284,8 @@ sub revert_split_path($$) {
                $svnpath = "$branch_name/$branch/$path";
        }
 
-       return $svnpath
+       $svnpath =~ s#/+$##;
+       return $svnpath;
 }
 
 sub get_file($$$) {
@@ -372,6 +377,10 @@ sub copy_path($$$$$$$$) {
        my($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;
 
        my($srcbranch,$srcpath) = split_path($rev,$oldpath);
+       unless(defined $srcbranch) {
+               print "Path not found when copying from $oldpath @ $rev\n";
+               return;
+       }
        my $therev = branch_rev($srcbranch, $rev);
        my $gitrev = $branches{$srcbranch}{$therev};
        unless($gitrev) {
@@ -761,8 +770,7 @@ if($orig_branch) {
        print "DONE; creating $orig_branch branch\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
        system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
                unless -f "$git_dir/refs/heads/master";
-       unlink("$git_dir/HEAD");
-       symlink("refs/heads/$orig_branch","$git_dir/HEAD");
+       system('git-update-ref', 'HEAD', "$orig_branch");
        unless ($opt_i) {
                system('git checkout');
                die "checkout failed: $?\n" if $?;