Code

Fix off-by-one in read_tree_recursive
[git.git] / git-svn.perl
index d967594ee70a53c1397da76f4b977191c4fd0561..931d1a37bcf7c905f9968b7ce58e0dd329007f3d 100755 (executable)
@@ -3297,7 +3297,7 @@ sub new {
 sub _mark_empty_symlinks {
        my ($git_svn, $switch_path) = @_;
        my $bool = Git::config_bool('svn.brokenSymlinkWorkaround');
-       return {} if (defined($bool) && ! $bool);
+       return {} if (!defined($bool)) || (defined($bool) && ! $bool);
 
        my %ret;
        my ($rev, $cmt) = $git_svn->last_rev_commit;
@@ -3384,15 +3384,18 @@ sub delete_entry {
        return undef if ($gpath eq '');
 
        # remove entire directories.
-       if (command('ls-tree', $self->{c}, '--', $gpath) =~ /^040000 tree/) {
+       my ($tree) = (command('ls-tree', '-z', $self->{c}, "./$gpath")
+                        =~ /\A040000 tree ([a-f\d]{40})\t\Q$gpath\E\0/);
+       if ($tree) {
                my ($ls, $ctx) = command_output_pipe(qw/ls-tree
                                                     -r --name-only -z/,
-                                                    $self->{c}, '--', $gpath);
+                                                    $tree);
                local $/ = "\0";
                while (<$ls>) {
                        chomp;
-                       $self->{gii}->remove($_);
-                       print "\tD\t$_\n" unless $::_q;
+                       my $rmpath = "$gpath/$_";
+                       $self->{gii}->remove($rmpath);
+                       print "\tD\t$rmpath\n" unless $::_q;
                }
                print "\tD\t$gpath/\n" unless $::_q;
                command_close_pipe($ls, $ctx);
@@ -3411,8 +3414,8 @@ sub open_file {
        goto out if is_path_ignored($path);
 
        my $gpath = $self->git_path($path);
-       ($mode, $blob) = (command('ls-tree', $self->{c}, '--', $gpath)
-                            =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
+       ($mode, $blob) = (command('ls-tree', '-z', $self->{c}, "./$gpath")
+                            =~ /\A(\d{6}) blob ([a-f\d]{40})\t\Q$gpath\E\0/);
        unless (defined $mode && defined $blob) {
                die "$path was not found in commit $self->{c} (r$rev)\n";
        }
@@ -4738,7 +4741,7 @@ sub run_pager {
 
 sub format_svn_date {
        # some systmes don't handle or mishandle %z, so be creative.
-       my $t = shift;
+       my $t = shift || time;
        my $gm = timelocal(gmtime($t));
        my $sign = qw( + + - )[ $t <=> $gm ];
        my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);