Skip to content

Commit

Permalink
git-archive: ignore prefix when checking file attribute
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
René Scharfe authored and gitster committed Apr 10, 2008
1 parent 3f36cbb commit ac7fa27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static time_t archive_time;
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)
Expand Down Expand Up @@ -251,8 +252,8 @@ static int write_tar_entry(const unsigned char *sha1,
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));
}
Expand All @@ -272,6 +273,7 @@ int write_tar_archive(struct archiver_args *args)
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);
Expand Down
6 changes: 4 additions & 2 deletions archive-zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static int verbose;
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;
Expand Down Expand Up @@ -197,8 +198,8 @@ static int write_zip_entry(const unsigned char *sha1,
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);
Expand Down Expand Up @@ -321,6 +322,7 @@ int write_zip_archive(struct archiver_args *args)
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);
Expand Down
15 changes: 14 additions & 1 deletion t/t5000-tar-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ test_expect_success \
'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 \
Expand All @@ -126,6 +127,18 @@ 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'
Expand Down

0 comments on commit ac7fa27

Please sign in to comment.