@matheusbsbs / matheus-bagliano / commits / 66f136252f
Fork 0

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>

Nguyễn Thái Ngọc Duy committed Dec 15, 2010 at 22:02 UTC 66f136252fe1998e2c1381c913795b5f56b6dc8c
8 files changed +22 -50
builtin/diff-files.c
+1 -1
@@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
61 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
62 rev.combine_merges = rev.dense_combined_merges = 1;
63
64 - if (read_cache_preload(rev.diffopt.paths) < 0) {
64 + if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
65 perror("read_cache_preload");
66 return -1;
67 }
builtin/diff.c
+2 -2
@@ -135,7 +135,7 @@ static int builtin_diff_index(struct rev_info *revs,
135 revs->max_count != -1 || revs->min_age != -1 ||
136 revs->max_age != -1)
137 usage(builtin_diff_usage);
138 - if (read_cache_preload(revs->diffopt.paths) < 0) {
138 + if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
139 perror("read_cache_preload");
140 return -1;
141 }
@@ -237,7 +237,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
237 revs->combine_merges = revs->dense_combined_merges = 1;
238
239 setup_work_tree();
240 - if (read_cache_preload(revs->diffopt.paths) < 0) {
240 + if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
241 perror("read_cache_preload");
242 return -1;
243 }
builtin/log.c
+1 -1
@@ -89,7 +89,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
89 rev->always_show_header = 0;
90 if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
91 rev->always_show_header = 0;
92 - if (rev->diffopt.nr_paths != 1)
92 + if (rev->diffopt.pathspec.nr != 1)
93 usage("git logs can only follow renames on one pathname at a time");
94 }
95 for (i = 1; i < argc; i++) {
diff-lib.c
+1 -1
@@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
501 active_nr = dst - active_cache;
502
503 init_revisions(&revs, NULL);
504 - revs.prune_data = opt->paths;
504 + revs.prune_data = opt->pathspec.raw;
505 tree = parse_tree_indirect(tree_sha1);
506 if (!tree)
507 die("bad tree object %s", sha1_to_hex(tree_sha1));
diff-no-index.c
+2 -2
@@ -260,8 +260,8 @@ void diff_no_index(struct rev_info *revs,
260 if (diff_setup_done(&revs->diffopt) < 0)
261 die("diff_setup_done failed");
262
263 - if (queue_diff(&revs->diffopt, revs->diffopt.paths[0],
264 - revs->diffopt.paths[1]))
263 + if (queue_diff(&revs->diffopt, revs->diffopt.pathspec.raw[0],
264 + revs->diffopt.pathspec.raw[1]))
265 exit(1);
266 diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
267 diffcore_std(&revs->diffopt);
diff.h
+1 -3
@@ -133,9 +133,7 @@ struct diff_options {
133 FILE *file;
134 int close_file;
135
136 - int nr_paths;
137 - const char **paths;
138 - int *pathlens;
136 + struct pathspec pathspec;
137 change_fn_t change;
138 add_remove_fn_t add_remove;
139 diff_format_fn_t format_callback;
revision.c
+1 -5
@@ -553,11 +553,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
553
554 left_first = left_count < right_count;
555 init_patch_ids(&ids);
556 - if (revs->diffopt.nr_paths) {
557 - ids.diffopts.nr_paths = revs->diffopt.nr_paths;
558 - ids.diffopts.paths = revs->diffopt.paths;
559 - ids.diffopts.pathlens = revs->diffopt.pathlens;
560 - }
556 + ids.diffopts.pathspec = revs->diffopt.pathspec;
557
558 /* Compute patch-ids for one side */
559 for (p = list; p; p = p->next) {
tree-diff.c
+13 -35
@@ -102,16 +102,17 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
102 int pathlen;
103 int never_interesting = -1;
104
105 - if (!opt->nr_paths)
105 + if (!opt->pathspec.nr)
106 return 2;
107
108 sha1 = tree_entry_extract(desc, &path, &mode);
109
110 pathlen = tree_entry_len(path, sha1);
111
112 - for (i = 0; i < opt->nr_paths; i++) {
113 - const char *match = opt->paths[i];
114 - int matchlen = opt->pathlens[i];
112 + for (i = 0; i < opt->pathspec.nr; i++) {
113 + const struct pathspec_item *item = opt->pathspec.items+i;
114 + const char *match = item->match;
115 + int matchlen = item->len;
116 int m = -1; /* signals that we haven't called strncmp() */
117
118 if (baselen >= matchlen) {
@@ -286,7 +287,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
287 if (DIFF_OPT_TST(opt, QUICK) &&
288 DIFF_OPT_TST(opt, HAS_CHANGES))
289 break;
289 - if (opt->nr_paths) {
290 + if (opt->pathspec.nr) {
291 if (!all_t1_interesting)
292 skip_uninteresting(t1, base, baselen, opt,
293 &all_t1_interesting);
@@ -349,7 +350,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
350 DIFF_OPT_SET(&diff_opts, RECURSIVE);
351 DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
352 diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
352 - diff_opts.single_follow = opt->paths[0];
353 + diff_opts.single_follow = opt->pathspec.raw[0];
354 diff_opts.break_opt = opt->break_opt;
355 paths[0] = NULL;
356 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
370 * diff_queued_diff, we will also use that as the path in
371 * the future!
372 */
372 - if ((p->status == 'R' || p->status == 'C') && !strcmp(p->two->path, opt->paths[0])) {
373 + if ((p->status == 'R' || p->status == 'C') &&
374 + !strcmp(p->two->path, opt->pathspec.raw[0])) {
375 /* Switch the file-pairs around */
376 q->queue[i] = choice;
377 choice = p;
378
379 /* Update the path we use from now on.. */
380 diff_tree_release_paths(opt);
379 - opt->paths[0] = xstrdup(p->one->path);
380 - diff_tree_setup_paths(opt->paths, opt);
381 + opt->pathspec.raw[0] = xstrdup(p->one->path);
382 + diff_tree_setup_paths(opt->pathspec.raw, opt);
383
384 /*
385 * 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_
454 return retval;
455 }
456
455 -static int count_paths(const char **paths)
456 -{
457 - int i = 0;
458 - while (*paths++)
459 - i++;
460 - return i;
461 -}
462 -
457 void diff_tree_release_paths(struct diff_options *opt)
458 {
465 - free(opt->pathlens);
459 + free_pathspec(&opt->pathspec);
460 }
461
462 void diff_tree_setup_paths(const char **p, struct diff_options *opt)
463 {
470 - opt->nr_paths = 0;
471 - opt->pathlens = NULL;
472 - opt->paths = NULL;
473 -
474 - if (p) {
475 - int i;
476 -
477 - opt->paths = p;
478 - opt->nr_paths = count_paths(p);
479 - if (opt->nr_paths == 0) {
480 - opt->pathlens = NULL;
481 - return;
482 - }
483 - opt->pathlens = xmalloc(opt->nr_paths * sizeof(int));
484 - for (i=0; i < opt->nr_paths; i++)
485 - opt->pathlens[i] = strlen(p[i]);
486 - }
464 + init_pathspec(&opt->pathspec, p);
465 }