mirror of
https://github.com/git/git
synced 2024-08-28 03:59:25 +00:00
tar-tree: Use the prefix field of a tar header
... to store parts of the path, if possible. This allows us to avoid writing extended headers in certain cases (long pathes can only be split at '/' chars). Also adds a file to the test repo with a 100 chars long directory name. Even old versions of tar that don't understand POSIX extended headers should be able to handle this testcase. Btw.: The longest path in the kernel tree currently has 70 chars. Together with a 30 chars long prefix this would already cross the field limit of 100 chars. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
86da1c567d
commit
4c691724f1
|
@ -34,6 +34,9 @@ test_expect_success \
|
||||||
mkdir a/bin &&
|
mkdir a/bin &&
|
||||||
cp /bin/sh a/bin &&
|
cp /bin/sh a/bin &&
|
||||||
ln -s a a/l1 &&
|
ln -s a a/l1 &&
|
||||||
|
(p=long_path_to_a_file && cd a &&
|
||||||
|
for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
|
||||||
|
echo text >file_with_long_path) &&
|
||||||
(cd a && find .) | sort >a.lst'
|
(cd a && find .) | sort >a.lst'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
|
|
24
tar-tree.c
24
tar-tree.c
|
@ -161,6 +161,16 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
|
||||||
return chksum;
|
return chksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_path_prefix(const struct strbuf *path, int maxlen)
|
||||||
|
{
|
||||||
|
int i = path->len;
|
||||||
|
if (i > maxlen)
|
||||||
|
i = maxlen;
|
||||||
|
while (i > 0 && path->buf[i] != '/')
|
||||||
|
i--;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
static void write_entry(const unsigned char *sha1, struct strbuf *path,
|
static void write_entry(const unsigned char *sha1, struct strbuf *path,
|
||||||
unsigned int mode, void *buffer, unsigned long size)
|
unsigned int mode, void *buffer, unsigned long size)
|
||||||
{
|
{
|
||||||
|
@ -195,9 +205,17 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (path->len > sizeof(header.name)) {
|
if (path->len > sizeof(header.name)) {
|
||||||
sprintf(header.name, "%s.data", sha1_to_hex(sha1));
|
int plen = get_path_prefix(path, sizeof(header.prefix));
|
||||||
strbuf_append_ext_header(&ext_header, "path",
|
int rest = path->len - plen - 1;
|
||||||
path->buf, path->len);
|
if (plen > 0 && rest <= sizeof(header.name)) {
|
||||||
|
memcpy(header.prefix, path->buf, plen);
|
||||||
|
memcpy(header.name, path->buf + plen + 1, rest);
|
||||||
|
} else {
|
||||||
|
sprintf(header.name, "%s.data",
|
||||||
|
sha1_to_hex(sha1));
|
||||||
|
strbuf_append_ext_header(&ext_header, "path",
|
||||||
|
path->buf, path->len);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
memcpy(header.name, path->buf, path->len);
|
memcpy(header.name, path->buf, path->len);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue