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>
This commit is contained in:

committed by
Junio C Hamano

parent
bed69a6e82
commit
c6c08f7e9a
31
archive.c
31
archive.c
@ -103,12 +103,30 @@ struct archiver_context {
|
|||||||
struct directory *bottom;
|
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,
|
static int write_archive_entry(const unsigned char *sha1, const char *base,
|
||||||
int baselen, const char *filename, unsigned mode, int stage,
|
int baselen, const char *filename, unsigned mode, int stage,
|
||||||
void *context)
|
void *context)
|
||||||
{
|
{
|
||||||
static struct strbuf path = STRBUF_INIT;
|
static struct strbuf path = STRBUF_INIT;
|
||||||
static struct attr_check *check;
|
const struct attr_check *check;
|
||||||
struct archiver_context *c = context;
|
struct archiver_context *c = context;
|
||||||
struct archiver_args *args = c->args;
|
struct archiver_args *args = c->args;
|
||||||
write_archive_entry_fn_t write_entry = c->write_entry;
|
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, '/');
|
strbuf_addch(&path, '/');
|
||||||
path_without_prefix = path.buf + args->baselen;
|
path_without_prefix = path.buf + args->baselen;
|
||||||
|
|
||||||
if (!check)
|
check = get_archive_attrs(path_without_prefix);
|
||||||
check = attr_check_initl("export-ignore", "export-subst", NULL);
|
if (check_attr_export_ignore(check))
|
||||||
if (!git_check_attr(path_without_prefix, check)) {
|
return 0;
|
||||||
if (ATTR_TRUE(check->items[0].value))
|
args->convert = check_attr_export_subst(check);
|
||||||
return 0;
|
|
||||||
args->convert = ATTR_TRUE(check->items[1].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
||||||
if (args->verbose)
|
if (args->verbose)
|
||||||
|
Reference in New Issue
Block a user