aboutsummaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-08-19 07:32:37 +0200
committerJunio C Hamano <gitster@pobox.com>2017-08-19 00:40:25 -0700
commit5ff247ac0cc9b2d09c8c24bd0c8df12eed94aebc (patch)
tree3491f059ec09b1fedd756f2f76ba7c700574500e /archive.c
parentc6c08f7e9a94d062fb2f90687156798e78cf8991 (diff)
downloadgit-5ff247ac0cc9b2d09c8c24bd0c8df12eed94aebc.tar.gz
git-5ff247ac0cc9b2d09c8c24bd0c8df12eed94aebc.tar.xz
archive: don't queue excluded directories
Reject directories with the attribute export-ignore already while queuing them. This prevents read_tree_recursive() from descending into them and this avoids write_archive_entry() rejecting them later on, which queue_or_write_archive_entry() is not prepared for. Borrow the existing strbuf to build the full path to avoid string copies and extra allocations; just make sure we restore the original value before moving on. Keep checking any other attributes in write_archive_entry() as before, but avoid checking them twice. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/archive.c b/archive.c
index 66f1abe73..2ad7e6cb9 100644
--- a/archive.c
+++ b/archive.c
@@ -121,17 +121,21 @@ static int check_attr_export_subst(const struct attr_check *check)
return check && ATTR_TRUE(check->items[1].value);
}
+static int should_queue_directories(const struct archiver_args *args)
+{
+ return args->pathspec.has_wildcard;
+}
+
static int write_archive_entry(const unsigned char *sha1, const char *base,
int baselen, const char *filename, unsigned mode, int stage,
void *context)
{
static struct strbuf path = STRBUF_INIT;
- const struct attr_check *check;
struct archiver_context *c = context;
struct archiver_args *args = c->args;
write_archive_entry_fn_t write_entry = c->write_entry;
- const char *path_without_prefix;
int err;
+ const char *path_without_prefix;
args->convert = 0;
strbuf_reset(&path);
@@ -143,10 +147,13 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
strbuf_addch(&path, '/');
path_without_prefix = path.buf + args->baselen;
- check = get_archive_attrs(path_without_prefix);
- if (check_attr_export_ignore(check))
- return 0;
- args->convert = check_attr_export_subst(check);
+ if (!S_ISDIR(mode) || !should_queue_directories(args)) {
+ const struct attr_check *check;
+ check = get_archive_attrs(path_without_prefix);
+ if (check_attr_export_ignore(check))
+ return 0;
+ args->convert = check_attr_export_subst(check);
+ }
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
if (args->verbose)
@@ -219,6 +226,17 @@ static int queue_or_write_archive_entry(const unsigned char *sha1,
}
if (S_ISDIR(mode)) {
+ size_t baselen = base->len;
+ const struct attr_check *check;
+
+ /* Borrow base, but restore its original value when done. */
+ strbuf_addstr(base, filename);
+ strbuf_addch(base, '/');
+ check = get_archive_attrs(base->buf);
+ strbuf_setlen(base, baselen);
+
+ if (check_attr_export_ignore(check))
+ return 0;
queue_directory(sha1, base, filename,
mode, stage, c);
return READ_TREE_RECURSIVE;
@@ -272,7 +290,7 @@ int write_archive_entries(struct archiver_args *args,
}
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
- args->pathspec.has_wildcard ?
+ should_queue_directories(args) ?
queue_or_write_archive_entry :
write_archive_entry_buf,
&context);