summaryrefslogtreecommitdiff
path: root/tar-tree.c
diff options
context:
space:
mode:
authorRene Scharfe <rene.scharfe@lsrfire.ath.cx>2006-03-25 23:21:07 +0100
committerJunio C Hamano <junkio@cox.net>2006-03-25 16:40:34 -0800
commit4c691724f175573a2dc4118782744cb0e852ab41 (patch)
treeb6dadb1e5cf67c2d458a89fc3d4ae7af84edc239 /tar-tree.c
parent86da1c567da0421649cb1e8e999311012c764337 (diff)
downloadgit-4c691724f175573a2dc4118782744cb0e852ab41.tar.gz
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>
Diffstat (limited to 'tar-tree.c')
-rw-r--r--tar-tree.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/tar-tree.c b/tar-tree.c
index 11bbc81e36..efab2b5420 100644
--- a/tar-tree.c
+++ b/tar-tree.c
@@ -161,6 +161,16 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
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,
unsigned int mode, void *buffer, unsigned long size)
{
@@ -195,9 +205,17 @@ static void write_entry(const unsigned char *sha1, struct strbuf *path,
return;
}
if (path->len > sizeof(header.name)) {
- sprintf(header.name, "%s.data", sha1_to_hex(sha1));
- strbuf_append_ext_header(&ext_header, "path",
- path->buf, path->len);
+ int plen = get_path_prefix(path, sizeof(header.prefix));
+ int rest = path->len - plen - 1;
+ 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
memcpy(header.name, path->buf, path->len);
}