@matheusbsbs / matheus-bagliano / commits / 6fb37f86bc
Fork 0

import-tars: support symlinks

Without this patch, symbolic links are turned into empty files. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 17, 2009 at 14:49 UTC 6fb37f86bce7cf19b4dbff2aa8a93df5ac5c4cbe
1 file changed +12 -5
contrib/fast-import/import-tars.perl
+12 -5
@@ -82,10 +82,16 @@ foreach my $tar_file (@ARGV)
82 $mtime = oct $mtime;
83 next if $typeflag == 5; # directory
84
85 - print FI "blob\n", "mark :$next_mark\n", "data $size\n";
86 - while ($size > 0 && read(I, $_, 512) == 512) {
87 - print FI substr($_, 0, $size);
88 - $size -= 512;
85 + print FI "blob\n", "mark :$next_mark\n";
86 + if ($typeflag == 2) { # symbolic link
87 + print FI "data ", length($linkname), "\n", $linkname;
88 + $mode = 0120000;
89 + } else {
90 + print FI "data $size\n";
91 + while ($size > 0 && read(I, $_, 512) == 512) {
92 + print FI substr($_, 0, $size);
93 + $size -= 512;
94 + }
95 }
96 print FI "\n";
97
@@ -118,7 +124,8 @@ EOF
124 {
125 my ($mark, $mode) = @{$files{$path}};
126 $path =~ s,^([^/]+)/,, if $have_top_dir;
121 - printf FI "M %o :%i %s\n", $mode & 0111 ? 0755 : 0644, $mark, $path;
127 + $mode = $mode & 0111 ? 0755 : 0644 unless $mode == 0120000;
128 + printf FI "M %o :%i %s\n", $mode, $mark, $path;
129 }
130 print FI "\n";
131