diff --git a/archive.c b/archive.c index 0ce628b..f79d005 100644 --- a/archive.c +++ b/archive.c @@ -147,12 +147,34 @@ static int write_archive_entry(const unsigned char *sha1, const char *base, return err; } +static int read_gitattr_to_index(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context) +{ + struct cache_entry *ce; + unsigned int size; + int len; + static int gitattr_len = 0; + + if (S_ISDIR(mode)) + return READ_TREE_RECURSIVE; + + len = strlen(pathname); + if (!gitattr_len) + gitattr_len = strlen(GITATTRIBUTES_FILE); + if (len < gitattr_len || strcmp(pathname+len-gitattr_len, GITATTRIBUTES_FILE)) + return 0; + size = cache_entry_size(len); + ce = xcalloc(1, size); + ce->ce_mode = create_ce_mode(mode); + ce->ce_flags = create_ce_flags(len, stage); + memcpy(ce->name, pathname, len+1); + hashcpy(ce->sha1, sha1); + return add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK); +} + int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry) { struct archiver_context context; - struct unpack_trees_options opts; - struct tree_desc t; int err; if (args->baselen > 0 && args->base[args->baselen - 1] == '/') { @@ -170,20 +192,8 @@ int write_archive_entries(struct archiver_args *args, context.args = args; context.write_entry = write_entry; - - /* - * Setup index and instruct attr to read index only - */ if (!args->worktree_attributes) { - memset(&opts, 0, sizeof(opts)); - opts.index_only = 1; - opts.head_idx = -1; - opts.src_index = &the_index; - opts.dst_index = &the_index; - opts.fn = oneway_merge; - init_tree_desc(&t, args->tree->buffer, args->tree->size); - if (unpack_trees(1, &t, &opts)) - return -1; + read_tree_recursive(args->tree, NULL, 0, 0, NULL, read_gitattr_to_index, NULL); git_attr_set_direction(GIT_ATTR_INDEX, &the_index); }