aboutsummaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-09-06 13:11:25 +0900
committerJunio C Hamano <gitster@pobox.com>2017-09-06 13:11:25 +0900
commita7d7f125e3c0e7e502e29e09df21d8471ee89edf (patch)
tree2db7e63b42ddb88bcf26889f30132e34dd3a2336 /archive.c
parent8b36f0b196225fc25588220acf921d011d4bf9a7 (diff)
parent5ff247ac0cc9b2d09c8c24bd0c8df12eed94aebc (diff)
downloadgit-a7d7f125e3c0e7e502e29e09df21d8471ee89edf.tar.gz
git-a7d7f125e3c0e7e502e29e09df21d8471ee89edf.tar.xz
Merge branch 'rs/archive-excluded-directory'
"git archive" did not work well with pathspecs and the export-ignore attribute. * rs/archive-excluded-directory: archive: don't queue excluded directories archive: factor out helper functions for handling attributes t5001: add tests for export-ignore attributes and exclude pathspecs
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/archive.c b/archive.c
index 557dd2db8..1ab8d3a1d 100644
--- a/archive.c
+++ b/archive.c
@@ -103,17 +103,39 @@ struct archiver_context {
struct directory *bottom;
};
+static const struct attr_check *get_archive_attrs(const char *path)
+{
+ static struct attr_check *check;
+ if (!check)
+ check = attr_check_initl("export-ignore", "export-subst", NULL);
+ return git_check_attr(path, check) ? NULL : check;
+}
+
+static int check_attr_export_ignore(const struct attr_check *check)
+{
+ return check && ATTR_TRUE(check->items[0].value);
+}
+
+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;
- static 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);
@@ -125,12 +147,12 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
strbuf_addch(&path, '/');
path_without_prefix = path.buf + args->baselen;
- if (!check)
- check = attr_check_initl("export-ignore", "export-subst", NULL);
- if (!git_check_attr(path_without_prefix, check)) {
- if (ATTR_TRUE(check->items[0].value))
+ 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 = ATTR_TRUE(check->items[1].value);
+ args->convert = check_attr_export_subst(check);
}
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
@@ -204,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;
@@ -257,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);