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:
parent
16dc36fea8
commit
66f136252f
@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
|
|||||||
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
|
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
|
||||||
rev.combine_merges = rev.dense_combined_merges = 1;
|
rev.combine_merges = rev.dense_combined_merges = 1;
|
||||||
|
|
||||||
if (read_cache_preload(rev.diffopt.paths) < 0) {
|
if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
|
||||||
perror("read_cache_preload");
|
perror("read_cache_preload");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ static int builtin_diff_index(struct rev_info *revs,
|
|||||||
revs->max_count != -1 || revs->min_age != -1 ||
|
revs->max_count != -1 || revs->min_age != -1 ||
|
||||||
revs->max_age != -1)
|
revs->max_age != -1)
|
||||||
usage(builtin_diff_usage);
|
usage(builtin_diff_usage);
|
||||||
if (read_cache_preload(revs->diffopt.paths) < 0) {
|
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
|
||||||
perror("read_cache_preload");
|
perror("read_cache_preload");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
|
|||||||
revs->combine_merges = revs->dense_combined_merges = 1;
|
revs->combine_merges = revs->dense_combined_merges = 1;
|
||||||
|
|
||||||
setup_work_tree();
|
setup_work_tree();
|
||||||
if (read_cache_preload(revs->diffopt.paths) < 0) {
|
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
|
||||||
perror("read_cache_preload");
|
perror("read_cache_preload");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
|
|||||||
rev->always_show_header = 0;
|
rev->always_show_header = 0;
|
||||||
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
|
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
|
||||||
rev->always_show_header = 0;
|
rev->always_show_header = 0;
|
||||||
if (rev->diffopt.nr_paths != 1)
|
if (rev->diffopt.pathspec.nr != 1)
|
||||||
usage("git logs can only follow renames on one pathname at a time");
|
usage("git logs can only follow renames on one pathname at a time");
|
||||||
}
|
}
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
|
@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
|
|||||||
active_nr = dst - active_cache;
|
active_nr = dst - active_cache;
|
||||||
|
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
revs.prune_data = opt->paths;
|
revs.prune_data = opt->pathspec.raw;
|
||||||
tree = parse_tree_indirect(tree_sha1);
|
tree = parse_tree_indirect(tree_sha1);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
die("bad tree object %s", sha1_to_hex(tree_sha1));
|
die("bad tree object %s", sha1_to_hex(tree_sha1));
|
||||||
|
@ -260,8 +260,8 @@ void diff_no_index(struct rev_info *revs,
|
|||||||
if (diff_setup_done(&revs->diffopt) < 0)
|
if (diff_setup_done(&revs->diffopt) < 0)
|
||||||
die("diff_setup_done failed");
|
die("diff_setup_done failed");
|
||||||
|
|
||||||
if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
|
if (queue_diff(&revs->diffopt, revs->diffopt.pathspec.raw[0],
|
||||||
revs->diffopt.paths[1]))
|
revs->diffopt.pathspec.raw[1]))
|
||||||
exit(1);
|
exit(1);
|
||||||
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
|
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
|
||||||
diffcore_std(&revs->diffopt);
|
diffcore_std(&revs->diffopt);
|
||||||
|
4
diff.h
4
diff.h
@ -133,9 +133,7 @@ struct diff_options {
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
int close_file;
|
int close_file;
|
||||||
|
|
||||||
int nr_paths;
|
struct pathspec pathspec;
|
||||||
const char **paths;
|
|
||||||
int *pathlens;
|
|
||||||
change_fn_t change;
|
change_fn_t change;
|
||||||
add_remove_fn_t add_remove;
|
add_remove_fn_t add_remove;
|
||||||
diff_format_fn_t format_callback;
|
diff_format_fn_t format_callback;
|
||||||
|
@ -553,11 +553,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
|
|||||||
|
|
||||||
left_first = left_count < right_count;
|
left_first = left_count < right_count;
|
||||||
init_patch_ids(&ids);
|
init_patch_ids(&ids);
|
||||||
if (revs->diffopt.nr_paths) {
|
ids.diffopts.pathspec = revs->diffopt.pathspec;
|
||||||
ids.diffopts.nr_paths = revs->diffopt.nr_paths;
|
|
||||||
ids.diffopts.paths = revs->diffopt.paths;
|
|
||||||
ids.diffopts.pathlens = revs->diffopt.pathlens;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Compute patch-ids for one side */
|
/* Compute patch-ids for one side */
|
||||||
for (p = list; p; p = p->next) {
|
for (p = list; p; p = p->next) {
|
||||||
|
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 pathlen;
|
||||||
int never_interesting = -1;
|
int never_interesting = -1;
|
||||||
|
|
||||||
if (!opt->nr_paths)
|
if (!opt->pathspec.nr)
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
sha1 = tree_entry_extract(desc, &path, &mode);
|
sha1 = tree_entry_extract(desc, &path, &mode);
|
||||||
|
|
||||||
pathlen = tree_entry_len(path, sha1);
|
pathlen = tree_entry_len(path, sha1);
|
||||||
|
|
||||||
for (i = 0; i < opt->nr_paths; i++) {
|
for (i = 0; i < opt->pathspec.nr; i++) {
|
||||||
const char *match = opt->paths[i];
|
const struct pathspec_item *item = opt->pathspec.items+i;
|
||||||
int matchlen = opt->pathlens[i];
|
const char *match = item->match;
|
||||||
|
int matchlen = item->len;
|
||||||
int m = -1; /* signals that we haven't called strncmp() */
|
int m = -1; /* signals that we haven't called strncmp() */
|
||||||
|
|
||||||
if (baselen >= matchlen) {
|
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) &&
|
if (DIFF_OPT_TST(opt, QUICK) &&
|
||||||
DIFF_OPT_TST(opt, HAS_CHANGES))
|
DIFF_OPT_TST(opt, HAS_CHANGES))
|
||||||
break;
|
break;
|
||||||
if (opt->nr_paths) {
|
if (opt->pathspec.nr) {
|
||||||
if (!all_t1_interesting)
|
if (!all_t1_interesting)
|
||||||
skip_uninteresting(t1, base, baselen, opt,
|
skip_uninteresting(t1, base, baselen, opt,
|
||||||
&all_t1_interesting);
|
&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, RECURSIVE);
|
||||||
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
|
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
|
||||||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
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;
|
diff_opts.break_opt = opt->break_opt;
|
||||||
paths[0] = NULL;
|
paths[0] = NULL;
|
||||||
diff_tree_setup_paths(paths, &diff_opts);
|
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
|
* diff_queued_diff, we will also use that as the path in
|
||||||
* the future!
|
* 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 */
|
/* Switch the file-pairs around */
|
||||||
q->queue[i] = choice;
|
q->queue[i] = choice;
|
||||||
choice = p;
|
choice = p;
|
||||||
|
|
||||||
/* Update the path we use from now on.. */
|
/* Update the path we use from now on.. */
|
||||||
diff_tree_release_paths(opt);
|
diff_tree_release_paths(opt);
|
||||||
opt->paths[0] = xstrdup(p->one->path);
|
opt->pathspec.raw[0] = xstrdup(p->one->path);
|
||||||
diff_tree_setup_paths(opt->paths, opt);
|
diff_tree_setup_paths(opt->pathspec.raw, opt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The caller expects us to return a set of vanilla
|
* 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;
|
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)
|
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)
|
void diff_tree_setup_paths(const char **p, struct diff_options *opt)
|
||||||
{
|
{
|
||||||
opt->nr_paths = 0;
|
init_pathspec(&opt->pathspec, p);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user