Code

Merge branch 'maint'
[git.git] / contrib / fast-import / import-tars.perl
index 26c42c978080c19316e0c4086c07ab2ab47cc7aa..23aeb257b9557cb146586868084ce1b20d7e7ac8 100755 (executable)
@@ -25,11 +25,14 @@ foreach my $tar_file (@ARGV)
        my $tar_name = $1;
 
        if ($tar_name =~ s/\.(tar\.gz|tgz)$//) {
-               open(I, '-|', 'gzcat', $tar_file) or die "Unable to gzcat $tar_file: $!\n";
+               open(I, '-|', 'gunzip', '-c', $tar_file)
+                       or die "Unable to gunzip -c $tar_file: $!\n";
        } elsif ($tar_name =~ s/\.(tar\.bz2|tbz2)$//) {
-               open(I, '-|', 'bzcat', $tar_file) or die "Unable to bzcat $tar_file: $!\n";
+               open(I, '-|', 'bunzip2', '-c', $tar_file)
+                       or die "Unable to bunzip2 -c $tar_file: $!\n";
        } elsif ($tar_name =~ s/\.tar\.Z$//) {
-               open(I, '-|', 'zcat', $tar_file) or die "Unable to zcat $tar_file: $!\n";
+               open(I, '-|', 'uncompress', '-c', $tar_file)
+                       or die "Unable to uncompress -c $tar_file: $!\n";
        } elsif ($tar_name =~ s/\.tar$//) {
                open(I, $tar_file) or die "Unable to open $tar_file: $!\n";
        } else {
@@ -48,11 +51,31 @@ foreach my $tar_file (@ARGV)
                        $prefix) = unpack 'Z100 Z8 Z8 Z8 Z12 Z12
                        Z8 Z1 Z100 Z6
                        Z2 Z32 Z32 Z8 Z8 Z*', $_;
-               last unless $name;
+               last unless length($name);
+               if ($name eq '././@LongLink') {
+                       # GNU tar extension
+                       if (read(I, $_, 512) != 512) {
+                               die ('Short archive');
+                       }
+                       $name = unpack 'Z257', $_;
+                       next unless $name;
+
+                       my $dummy;
+                       if (read(I, $_, 512) != 512) {
+                               die ('Short archive');
+                       }
+                       ($dummy, $mode, $uid, $gid, $size, $mtime,
+                       $chksum, $typeflag, $linkname, $magic,
+                       $version, $uname, $gname, $devmajor, $devminor,
+                       $prefix) = unpack 'Z100 Z8 Z8 Z8 Z12 Z12
+                       Z8 Z1 Z100 Z6
+                       Z2 Z32 Z32 Z8 Z8 Z*', $_;
+               }
+               next if $name =~ m{/\z};
                $mode = oct $mode;
                $size = oct $size;
                $mtime = oct $mtime;
-               next if $mode & 0040000;
+               next if $typeflag == 5; # directory
 
                print FI "blob\n", "mark :$next_mark\n", "data $size\n";
                while ($size > 0 && read(I, $_, 512) == 512) {
@@ -61,7 +84,12 @@ foreach my $tar_file (@ARGV)
                }
                print FI "\n";
 
-               my $path = "$prefix$name";
+               my $path;
+               if ($prefix) {
+                       $path = "$prefix/$name";
+               } else {
+                       $path = "$name";
+               }
                $files{$path} = [$next_mark++, $mode];
 
                $commit_time = $mtime if $mtime > $commit_time;
@@ -83,10 +111,8 @@ EOF
        foreach my $path (keys %files)
        {
                my ($mark, $mode) = @{$files{$path}};
-               my $git_mode = 0644;
-               $git_mode |= 0700 if $mode & 0111;
                $path =~ s,^([^/]+)/,, if $have_top_dir;
-               printf FI "M %o :%i %s\n", $git_mode, $mark, $path;
+               printf FI "M %o :%i %s\n", $mode & 0111 ? 0755 : 0644, $mark, $path;
        }
        print FI "\n";