Skip to content

Commit c6c08f7

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bed69a6 commit c6c08f7

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

archive.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,30 @@ struct archiver_context {
103103
struct directory *bottom;
104104
};
105105

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+
106124
static int write_archive_entry(const unsigned char *sha1, const char *base,
107125
int baselen, const char *filename, unsigned mode, int stage,
108126
void *context)
109127
{
110128
static struct strbuf path = STRBUF_INIT;
111-
static struct attr_check *check;
129+
const struct attr_check *check;
112130
struct archiver_context *c = context;
113131
struct archiver_args *args = c->args;
114132
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,
125143
strbuf_addch(&path, '/');
126144
path_without_prefix = path.buf + args->baselen;
127145

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);
135150

136151
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
137152
if (args->verbose)

0 commit comments

Comments
 (0)