Convert struct diff_options to use struct pathspec
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
16dc36fea8
commit
66f136252f
48
tree-diff.c
48
tree-diff.c
@ -102,16 +102,17 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
|
||||
int pathlen;
|
||||
int never_interesting = -1;
|
||||
|
||||
if (!opt->nr_paths)
|
||||
if (!opt->pathspec.nr)
|
||||
return 2;
|
||||
|
||||
sha1 = tree_entry_extract(desc, &path, &mode);
|
||||
|
||||
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 < opt->pathspec.nr; i++) {
|
||||
const struct pathspec_item *item = opt->pathspec.items+i;
|
||||
const char *match = item->match;
|
||||
int matchlen = item->len;
|
||||
int m = -1; /* signals that we haven't called strncmp() */
|
||||
|
||||
if (baselen >= matchlen) {
|
||||
@ -286,7 +287,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
|
||||
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);
|
||||
@ -349,7 +350,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
|
||||
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);
|
||||
@ -369,15 +370,16 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
|
||||
* 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
|
||||
@ -452,36 +454,12 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user