Convert read_tree{,_recursive} to support struct pathspec
This patch changes behavior of the two functions. Previously it does prefix matching only. Now it can also do wildcard matching. All callers are updated. Some gain wildcard matching (archive, checkout), others reset pathspec_item.has_wildcard to retain old behavior (ls-files, ls-tree as they are plumbing). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ffd31f661d
commit
f0096c06bc
16
archive.c
16
archive.c
@ -157,6 +157,7 @@ int write_archive_entries(struct archiver_args *args,
|
||||
struct archiver_context context;
|
||||
struct unpack_trees_options opts;
|
||||
struct tree_desc t;
|
||||
struct pathspec pathspec;
|
||||
int err;
|
||||
|
||||
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
|
||||
@ -191,8 +192,10 @@ int write_archive_entries(struct archiver_args *args,
|
||||
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
|
||||
}
|
||||
|
||||
err = read_tree_recursive(args->tree, "", 0, 0, args->pathspec,
|
||||
init_pathspec(&pathspec, args->pathspec);
|
||||
err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
|
||||
write_archive_entry, &context);
|
||||
free_pathspec(&pathspec);
|
||||
if (err == READ_TREE_RECURSIVE)
|
||||
err = 0;
|
||||
return err;
|
||||
@ -221,11 +224,14 @@ static int reject_entry(const unsigned char *sha1, const char *base,
|
||||
|
||||
static int path_exists(struct tree *tree, const char *path)
|
||||
{
|
||||
const char *pathspec[] = { path, NULL };
|
||||
const char *paths[] = { path, NULL };
|
||||
struct pathspec pathspec;
|
||||
int ret;
|
||||
|
||||
if (read_tree_recursive(tree, "", 0, 0, pathspec, reject_entry, NULL))
|
||||
return 1;
|
||||
return 0;
|
||||
init_pathspec(&pathspec, paths);
|
||||
ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
|
||||
free_pathspec(&pathspec);
|
||||
return ret != 0;
|
||||
}
|
||||
|
||||
static void parse_pathspec_arg(const char **pathspec,
|
||||
|
Reference in New Issue
Block a user