Merge branch 'nd/struct-pathspec'

* nd/struct-pathspec:
  pathspec: rename per-item field has_wildcard to use_wildcard
  Improve tree_entry_interesting() handling code
  Convert read_tree{,_recursive} to support struct pathspec
  Reimplement read_tree_recursive() using tree_entry_interesting()
This commit is contained in:
Junio C Hamano
2011-05-06 10:50:06 -07:00
15 changed files with 148 additions and 169 deletions

View File

@ -79,7 +79,10 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
static int read_tree_some(struct tree *tree, const char **pathspec)
{
read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
struct pathspec ps;
init_pathspec(&ps, pathspec);
read_tree_recursive(tree, "", 0, 0, &ps, update_some, NULL);
free_pathspec(&ps);
/* update the index with the given tree's info
* for all args, expanding wildcards, and exit

View File

@ -533,18 +533,18 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
struct tree_desc *tree, struct strbuf *base, int tn_len)
{
int hit = 0, matched = 0;
int hit = 0, match = 0;
struct name_entry entry;
int old_baselen = base->len;
while (tree_entry(tree, &entry)) {
int te_len = tree_entry_len(entry.path, entry.sha1);
if (matched != 2) {
matched = tree_entry_interesting(&entry, base, tn_len, pathspec);
if (matched == -1)
break; /* no more matches */
if (!matched)
if (match != 2) {
match = tree_entry_interesting(&entry, base, tn_len, pathspec);
if (match < 0)
break;
if (match == 0)
continue;
}

View File

@ -414,6 +414,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
struct rev_info rev;
struct object_array_entry *objects;
struct setup_revision_opt opt;
struct pathspec match_all;
int i, count, ret = 0;
git_config(git_log_config, NULL);
@ -421,6 +422,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
init_pathspec(&match_all, NULL);
init_revisions(&rev, prefix);
rev.diff = 1;
rev.always_show_header = 1;
@ -467,7 +469,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
name,
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
show_tree_object, NULL);
rev.shown_one = 1;
break;

View File

@ -338,7 +338,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
{
struct tree *tree;
unsigned char sha1[20];
const char **match;
struct pathspec pathspec;
struct cache_entry *last_stage0 = NULL;
int i;
@ -360,10 +360,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
static const char *(matchbuf[2]);
matchbuf[0] = prefix;
matchbuf[1] = NULL;
match = matchbuf;
init_pathspec(&pathspec, matchbuf);
pathspec.items[0].use_wildcard = 0;
} else
match = NULL;
if (read_tree(tree, 1, match))
init_pathspec(&pathspec, NULL);
if (read_tree(tree, 1, &pathspec))
die("unable to read tree entries %s", tree_name);
for (i = 0; i < active_nr; i++) {

View File

@ -19,7 +19,7 @@ static int line_termination = '\n';
#define LS_SHOW_SIZE 16
static int abbrev;
static int ls_options;
static const char **pathspec;
static struct pathspec pathspec;
static int chomp_prefix;
static const char *ls_tree_prefix;
@ -35,7 +35,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
if (ls_options & LS_RECURSIVE)
return 1;
s = pathspec;
s = pathspec.raw;
if (!s)
return 0;
@ -120,7 +120,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
{
unsigned char sha1[20];
struct tree *tree;
int full_tree = 0;
int i, full_tree = 0;
const struct option ls_tree_options[] = {
OPT_BIT('d', NULL, &ls_options, "only show trees",
LS_TREE_ONLY),
@ -166,11 +166,14 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
if (get_sha1(argv[0], sha1))
die("Not a valid object name %s", argv[0]);
pathspec = get_pathspec(prefix, argv + 1);
init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
for (i = 0; i < pathspec.nr; i++)
pathspec.items[i].use_wildcard = 0;
pathspec.has_wildcard = 0;
tree = parse_tree_indirect(sha1);
if (!tree)
die("not a tree object");
read_tree_recursive(tree, "", 0, 0, pathspec, show_tree, NULL);
read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
return 0;
}