* - zero for no
* - negative for "no, and no subsequent entries will be either"
*/
-static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
+static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct pathspec *ps)
{
- const char *path;
- const unsigned char *sha1;
- unsigned mode;
int i;
int pathlen;
int never_interesting = -1;
- if (!opt->nr_paths)
+ if (!ps || !ps->nr)
return 2;
- sha1 = tree_entry_extract(desc, &path, &mode);
+ pathlen = tree_entry_len(entry->path, entry->sha1);
- pathlen = tree_entry_len(path, sha1);
-
- for (i = 0; i < opt->nr_paths; i++) {
- const char *match = opt->paths[i];
- int matchlen = opt->pathlens[i];
+ for (i = 0; i < ps->nr; i++) {
+ const struct pathspec_item *item = ps->items+i;
+ const char *match = item->match;
+ int matchlen = item->len;
int m = -1; /* signals that we haven't called strncmp() */
if (baselen >= matchlen) {
* Does match sort strictly earlier than path
* with their common parts?
*/
- m = strncmp(match, path,
+ m = strncmp(match, entry->path,
(matchlen < pathlen) ? matchlen : pathlen);
if (m < 0)
continue;
if (matchlen > pathlen) {
if (match[pathlen] != '/')
continue;
- if (!S_ISDIR(mode))
+ if (!S_ISDIR(entry->mode))
continue;
}
* we cheated and did not do strncmp(), so we do
* that here.
*/
- m = strncmp(match, path, pathlen);
+ m = strncmp(match, entry->path, pathlen);
/*
* If common part matched earlier then it is a hit,
if (all_interesting)
show = 1;
else {
- show = tree_entry_interesting(desc, base, baselen,
- opt);
+ show = tree_entry_interesting(&desc->entry, base, baselen, &opt->pathspec);
if (show == 2)
all_interesting = 1;
}
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
{
while (t->size) {
- int show = tree_entry_interesting(t, base, baselen, opt);
+ int show = tree_entry_interesting(&t->entry, base, baselen, &opt->pathspec);
if (show == 2)
*all_interesting = 1;
if (!show) {
if (DIFF_OPT_TST(opt, QUICK) &&
DIFF_OPT_TST(opt, HAS_CHANGES))
break;
- if (opt->nr_paths) {
+ if (opt->pathspec.nr) {
if (!all_t1_interesting)
skip_uninteresting(t1, base, baselen, opt,
&all_t1_interesting);
DIFF_OPT_SET(&diff_opts, RECURSIVE);
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
- diff_opts.single_follow = opt->paths[0];
+ diff_opts.single_follow = opt->pathspec.raw[0];
diff_opts.break_opt = opt->break_opt;
paths[0] = NULL;
diff_tree_setup_paths(paths, &diff_opts);
* diff_queued_diff, we will also use that as the path in
* the future!
*/
- if ((p->status == 'R' || p->status == 'C') && !strcmp(p->two->path, opt->paths[0])) {
+ if ((p->status == 'R' || p->status == 'C') &&
+ !strcmp(p->two->path, opt->pathspec.raw[0])) {
/* Switch the file-pairs around */
q->queue[i] = choice;
choice = p;
/* Update the path we use from now on.. */
diff_tree_release_paths(opt);
- opt->paths[0] = xstrdup(p->one->path);
- diff_tree_setup_paths(opt->paths, opt);
+ opt->pathspec.raw[0] = xstrdup(p->one->path);
+ diff_tree_setup_paths(opt->pathspec.raw, opt);
/*
* The caller expects us to return a set of vanilla
return retval;
}
-static int count_paths(const char **paths)
-{
- int i = 0;
- while (*paths++)
- i++;
- return i;
-}
-
void diff_tree_release_paths(struct diff_options *opt)
{
- free(opt->pathlens);
+ free_pathspec(&opt->pathspec);
}
void diff_tree_setup_paths(const char **p, struct diff_options *opt)
{
- opt->nr_paths = 0;
- opt->pathlens = NULL;
- opt->paths = NULL;
-
- if (p) {
- int i;
-
- opt->paths = p;
- opt->nr_paths = count_paths(p);
- if (opt->nr_paths == 0) {
- opt->pathlens = NULL;
- return;
- }
- opt->pathlens = xmalloc(opt->nr_paths * sizeof(int));
- for (i=0; i < opt->nr_paths; i++)
- opt->pathlens[i] = strlen(p[i]);
- }
+ init_pathspec(&opt->pathspec, p);
}