aboutsummaryrefslogtreecommitdiff
path: root/archive-tar.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2007-05-19 00:09:41 +0200
committerJunio C Hamano <junkio@cox.net>2007-05-18 16:36:45 -0700
commit5e6cfc80e26a4d0ebac38cff74c2cdebbe66cd27 (patch)
tree6f816b7b8ea0c284aa9c25c440ecca64c514b83c /archive-tar.c
parent4229aa5141b5d7716d283fa8625209b59398d7ba (diff)
downloadgit-5e6cfc80e26a4d0ebac38cff74c2cdebbe66cd27.tar.gz
git-5e6cfc80e26a4d0ebac38cff74c2cdebbe66cd27.tar.xz
git-archive: convert archive entries like checkouts do
As noted by Johan Herland, git-archive is a kind of checkout and needs to apply any checkout filters that might be configured. This patch adds the convenience function convert_sha1_file which returns a buffer containing the object's contents, after converting, if necessary (i.e. it's a combination of read_sha1_file and convert_to_working_tree). Direct calls to read_sha1_file in git-archive are then replaced by calls to convert_sha1_file. Since convert_sha1_file expects its path argument to be NUL-terminated -- a convention it inherits from convert_to_working_tree -- the patch also changes the path handling in archive-tar.c to always NUL-terminate the string. It used to solely rely on the len field of struct strbuf before. archive-zip.c already NUL-terminates the path and thus needs no such change. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'archive-tar.c')
-rw-r--r--archive-tar.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/archive-tar.c b/archive-tar.c
index 56ff35696..33e76576f 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -82,12 +82,13 @@ static void strbuf_append_string(struct strbuf *sb, const char *s)
{
int slen = strlen(s);
int total = sb->len + slen;
- if (total > sb->alloc) {
- sb->buf = xrealloc(sb->buf, total);
- sb->alloc = total;
+ if (total + 1 > sb->alloc) {
+ sb->buf = xrealloc(sb->buf, total + 1);
+ sb->alloc = total + 1;
}
memcpy(sb->buf + sb->len, s, slen);
sb->len = total;
+ sb->buf[total] = '\0';
}
/*
@@ -270,20 +271,21 @@ static int write_tar_entry(const unsigned char *sha1,
path.alloc = PATH_MAX;
path.len = path.eof = 0;
}
- if (path.alloc < baselen + filenamelen) {
+ if (path.alloc < baselen + filenamelen + 1) {
free(path.buf);
- path.buf = xmalloc(baselen + filenamelen);
- path.alloc = baselen + filenamelen;
+ path.buf = xmalloc(baselen + filenamelen + 1);
+ path.alloc = baselen + filenamelen + 1;
}
memcpy(path.buf, base, baselen);
memcpy(path.buf + baselen, filename, filenamelen);
path.len = baselen + filenamelen;
+ path.buf[path.len] = '\0';
if (S_ISDIR(mode) || S_ISDIRLNK(mode)) {
strbuf_append_string(&path, "/");
buffer = NULL;
size = 0;
} else {
- buffer = read_sha1_file(sha1, &type, &size);
+ buffer = convert_sha1_file(path.buf, sha1, mode, &type, &size);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
}