summaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-08-19 05:29:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-08-19 07:40:23 (GMT)
commitc6c08f7e9a94d062fb2f90687156798e78cf8991 (patch)
tree5384ab091ed6098a83003e6568c1079dfbef540c /archive.c
parentbed69a6e82bbef99159f9051fd4581cd37c9acf6 (diff)
downloadgit-c6c08f7e9a94d062fb2f90687156798e78cf8991.zip
git-c6c08f7e9a94d062fb2f90687156798e78cf8991.tar.gz
git-c6c08f7e9a94d062fb2f90687156798e78cf8991.tar.bz2
archive: factor out helper functions for handling attributes
Add helpers for accessing attributes that encapsulate the details of how to retrieve their values. 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.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/archive.c b/archive.c
index 60b3035..66f1abe 100644
--- a/archive.c
+++ b/archive.c
@@ -103,12 +103,30 @@ 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 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;
+ 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;
@@ -125,13 +143,10 @@ 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))
- return 0;
- args->convert = ATTR_TRUE(check->items[1].value);
- }
+ 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)