summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f36cbb)
raw | patch | inline | side by side (parent: 3f36cbb)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Wed, 9 Apr 2008 21:14:43 +0000 (23:14 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 10 Apr 2008 07:20:38 +0000 (00:20 -0700) |
Ulrik Sverdrup noticed that git-archive doesn't correctly apply the attribute
export-subst when the option --prefix is given, too.
When it checked if a file has the attribute turned on, git-archive would try
to look up the full path -- including the prefix -- in .gitattributes. That's
wrong, as the prefix doesn't need to have any relation to any existing
directories, tracked or not.
This patch makes git-archive ignore the prefix when looking up if value of the
attribute export-subst for a file.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
export-subst when the option --prefix is given, too.
When it checked if a file has the attribute turned on, git-archive would try
to look up the full path -- including the prefix -- in .gitattributes. That's
wrong, as the prefix doesn't need to have any relation to any existing
directories, tracked or not.
This patch makes git-archive ignore the prefix when looking up if value of the
attribute export-subst for a file.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-tar.c | patch | blob | history | |
archive-zip.c | patch | blob | history | |
t/t5000-tar-tree.sh | patch | blob | history |
diff --git a/archive-tar.c b/archive-tar.c
index 30aa2e23fdbb1630dffb27db4509bc529bbd884a..4add80284e4570d1da44861e9025fa75eeb775d6 100644 (file)
--- a/archive-tar.c
+++ b/archive-tar.c
static int tar_umask = 002;
static int verbose;
static const struct commit *commit;
+static size_t base_len;
/* writes out the whole block, but only if it is full */
static void write_if_needed(void)
buffer = NULL;
size = 0;
} else {
- buffer = sha1_file_to_archive(path.buf, sha1, mode, &type,
- &size, commit);
+ buffer = sha1_file_to_archive(path.buf + base_len, sha1, mode,
+ &type, &size, commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
}
archive_time = args->time;
verbose = args->verbose;
commit = args->commit;
+ base_len = args->base ? strlen(args->base) : 0;
if (args->commit_sha1)
write_global_extended_header(args->commit_sha1);
diff --git a/archive-zip.c b/archive-zip.c
index 74e30f6205f41112dc2bafe9371a790aca55f70c..18c0f8710c6150e3b0211d311a70bf4b34608370 100644 (file)
--- a/archive-zip.c
+++ b/archive-zip.c
static int zip_date;
static int zip_time;
static const struct commit *commit;
+static size_t base_len;
static unsigned char *zip_dir;
static unsigned int zip_dir_size;
if (S_ISREG(mode) && zlib_compression_level != 0)
method = 8;
result = 0;
- buffer = sha1_file_to_archive(path, sha1, mode, &type, &size,
- commit);
+ buffer = sha1_file_to_archive(path + base_len, sha1, mode,
+ &type, &size, commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
crc = crc32(crc, buffer, size);
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
verbose = args->verbose;
commit = args->commit;
+ base_len = args->base ? strlen(args->base) : 0;
if (args->base && plen > 0 && args->base[plen - 1] == '/') {
char *base = xstrdup(args->base);
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index dca2067b2d0bcd4423d843561b9275be50fe0da3..fa62b6aa21f5d8f8774b7f2af3a4cd60b8c0d761 100755 (executable)
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
'diff -r a c/prefix/a'
test_expect_success \
- 'create an archive with a substfiles' \
+ 'create archives with substfiles' \
'echo "substfile?" export-subst >a/.gitattributes &&
git archive HEAD >f.tar &&
+ git archive --prefix=prefix/ HEAD >g.tar &&
rm a/.gitattributes'
test_expect_success \
diff a/substfile2 f/a/substfile2
'
+test_expect_success \
+ 'extract substfiles from archive with prefix' \
+ '(mkdir g && cd g && $TAR xf -) <g.tar'
+
+test_expect_success \
+ 'validate substfile contents from archive with prefix' \
+ 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
+ >g/prefix/a/substfile1.expected &&
+ diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
+ diff a/substfile2 g/prefix/a/substfile2
+'
+
test_expect_success \
'git archive --format=zip' \
'git archive --format=zip HEAD >d.zip'