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>
René Scharfe committed
Aug 19, 2017 at 07:29 UTC
c6c08f7e9a94d062fb2f90687156798e78cf8991
1 file changed
+23
-8
archive.c
+23
-8
@@ -103,12 +103,30 @@ struct archiver_context {
103
struct directory *bottom;
104
};
105
106
+static const struct attr_check *get_archive_attrs(const char *path)
107
+{
108
+ static struct attr_check *check;
109
+ if (!check)
110
+ check = attr_check_initl("export-ignore", "export-subst", NULL);
111
+ return git_check_attr(path, check) ? NULL : check;
112
+}
113
+
114
+static int check_attr_export_ignore(const struct attr_check *check)
115
+{
116
+ return check && ATTR_TRUE(check->items[0].value);
117
+}
118
+
119
+static int check_attr_export_subst(const struct attr_check *check)
120
+{
121
+ return check && ATTR_TRUE(check->items[1].value);
122
+}
123
+
124
static int write_archive_entry(const unsigned char *sha1, const char *base,
125
int baselen, const char *filename, unsigned mode, int stage,
126
void *context)
127
{
128
static struct strbuf path = STRBUF_INIT;
111
- static struct attr_check *check;
129
+ const struct attr_check *check;
130
struct archiver_context *c = context;
131
struct archiver_args *args = c->args;
132
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,
143
strbuf_addch(&path, '/');
144
path_without_prefix = path.buf + args->baselen;
145
128
- if (!check)
129
- check = attr_check_initl("export-ignore", "export-subst", NULL);
130
- if (!git_check_attr(path_without_prefix, check)) {
131
- if (ATTR_TRUE(check->items[0].value))
132
- return 0;
133
- args->convert = ATTR_TRUE(check->items[1].value);
134
- }
146
+ check = get_archive_attrs(path_without_prefix);
147
+ if (check_attr_export_ignore(check))
148
+ return 0;
149
+ args->convert = check_attr_export_subst(check);
150
151
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
152
if (args->verbose)