Skip to content

Commit 04e0869

Browse files
dschogitster
authored andcommitted
import-tars: support hard links
Previously, we simply treated hard links as if they were plain files with size 0, ignoring the link type "1" and hence the link target. What we should do instead, of course, is to use the link target to get at the import mark for the contents, even if we cannot recreate the hard link per se, as Git has no concept of hard links. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e465796 commit 04e0869

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

contrib/fast-import/import-tars.perl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,35 @@
9696
$mtime = oct $mtime;
9797
next if $typeflag == 5; # directory
9898

99-
print FI "blob\n", "mark :$next_mark\n";
100-
if ($typeflag == 2) { # symbolic link
101-
print FI "data ", length($linkname), "\n", $linkname;
102-
$mode = 0120000;
103-
} else {
104-
print FI "data $size\n";
105-
while ($size > 0 && read(I, $_, 512) == 512) {
106-
print FI substr($_, 0, $size);
107-
$size -= 512;
99+
if ($typeflag != 1) { # handle hard links later
100+
print FI "blob\n", "mark :$next_mark\n";
101+
if ($typeflag == 2) { # symbolic link
102+
print FI "data ", length($linkname), "\n",
103+
$linkname;
104+
$mode = 0120000;
105+
} else {
106+
print FI "data $size\n";
107+
while ($size > 0 && read(I, $_, 512) == 512) {
108+
print FI substr($_, 0, $size);
109+
$size -= 512;
110+
}
108111
}
112+
print FI "\n";
109113
}
110-
print FI "\n";
111114

112115
my $path;
113116
if ($prefix) {
114117
$path = "$prefix/$name";
115118
} else {
116119
$path = "$name";
117120
}
118-
$files{$path} = [$next_mark++, $mode];
121+
122+
if ($typeflag == 1) { # hard link
123+
$linkname = "$prefix/$linkname" if $prefix;
124+
$files{$path} = [ $files{$linkname}->[0], $mode ];
125+
} else {
126+
$files{$path} = [$next_mark++, $mode];
127+
}
119128

120129
$author_time = $mtime if $mtime > $author_time;
121130
$path =~ m,^([^/]+)/,;

0 commit comments

Comments
 (0)