@matheusbsbs / matheus-bagliano / commits / b8fee3a388
Fork 0

git-svn: fix ls-tree usage with dash-prefixed paths

To find the blob object name given a tree and pathname, we were incorrectly calling "git ls-tree" with a "--" argument followed by the pathname of the file we wanted to get. git ls-tree <TREE> -- --dashed/path/name.c Unlike many command-line interfaces, the "--" alone does not symbolize the end of non-option arguments on the command-line. ls-tree interprets the "--" as a prefix to match against, thus the entire contents of the --dashed/* hierarchy would be returned because the "--" matches "--dashed" and every path under it. Thanks to Anton Gyllenberg for pointing me toward the Twisted repository as a real-world example of this case. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Mar 28, 2009 at 23:10 UTC b8fee3a3884b4a18c2f0b5313255dd180c44ab78
1 file changed +9 -6
git-svn.perl
+9 -6
@@ -3384,15 +3384,18 @@ sub delete_entry {
3384 return undef if ($gpath eq '');
3385
3386 # remove entire directories.
3387 - if (command('ls-tree', $self->{c}, '--', $gpath) =~ /^040000 tree/) {
3387 + my ($tree) = (command('ls-tree', '-z', $self->{c}, "./$gpath")
3388 + =~ /\A040000 tree ([a-f\d]{40})\t\Q$gpath\E\0/);
3389 + if ($tree) {
3390 my ($ls, $ctx) = command_output_pipe(qw/ls-tree
3391 -r --name-only -z/,
3390 - $self->{c}, '--', $gpath);
3392 + $tree);
3393 local $/ = "\0";
3394 while (<$ls>) {
3395 chomp;
3394 - $self->{gii}->remove($_);
3395 - print "\tD\t$_\n" unless $::_q;
3396 + my $rmpath = "$gpath/$_";
3397 + $self->{gii}->remove($rmpath);
3398 + print "\tD\t$rmpath\n" unless $::_q;
3399 }
3400 print "\tD\t$gpath/\n" unless $::_q;
3401 command_close_pipe($ls, $ctx);
@@ -3411,8 +3414,8 @@ sub open_file {
3414 goto out if is_path_ignored($path);
3415
3416 my $gpath = $self->git_path($path);
3414 - ($mode, $blob) = (command('ls-tree', $self->{c}, '--', $gpath)
3415 - =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
3417 + ($mode, $blob) = (command('ls-tree', '-z', $self->{c}, "./$gpath")
3418 + =~ /\A(\d{6}) blob ([a-f\d]{40})\t\Q$gpath\E\0/);
3419 unless (defined $mode && defined $blob) {
3420 die "$path was not found in commit $self->{c} (r$rev)\n";
3421 }