Skip to content

Commit 9522dd1

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent b508df4 commit 9522dd1

File tree

8 files changed

+20
-50
lines changed

8 files changed

+20
-50
lines changed

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
6161
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
6262
rev.combine_merges = rev.dense_combined_merges = 1;
6363

64-
if (read_cache_preload(rev.diffopt.paths) < 0) {
64+
if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) {
6565
perror("read_cache_preload");
6666
return -1;
6767
}

builtin/diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int builtin_diff_index(struct rev_info *revs,
135135
revs->max_count != -1 || revs->min_age != -1 ||
136136
revs->max_age != -1)
137137
usage(builtin_diff_usage);
138-
if (read_cache_preload(revs->diffopt.paths) < 0) {
138+
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
139139
perror("read_cache_preload");
140140
return -1;
141141
}
@@ -237,7 +237,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
237237
revs->combine_merges = revs->dense_combined_merges = 1;
238238

239239
setup_work_tree();
240-
if (read_cache_preload(revs->diffopt.paths) < 0) {
240+
if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) {
241241
perror("read_cache_preload");
242242
return -1;
243243
}

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
8989
rev->always_show_header = 0;
9090
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
9191
rev->always_show_header = 0;
92-
if (rev->diffopt.nr_paths != 1)
92+
if (rev->diffopt.pathspec.nr != 1)
9393
usage("git logs can only follow renames on one pathname at a time");
9494
}
9595
for (i = 1; i < argc; i++) {

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
501501
active_nr = dst - active_cache;
502502

503503
init_revisions(&revs, NULL);
504-
revs.prune_data = opt->paths;
504+
revs.prune_data = opt->pathspec.raw;
505505
tree = parse_tree_indirect(tree_sha1);
506506
if (!tree)
507507
die("bad tree object %s", sha1_to_hex(tree_sha1));

diff-no-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ void diff_no_index(struct rev_info *revs,
260260
if (diff_setup_done(&revs->diffopt) < 0)
261261
die("diff_setup_done failed");
262262

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]))
265265
exit(1);
266266
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
267267
diffcore_std(&revs->diffopt);

diff.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ struct diff_options {
133133
FILE *file;
134134
int close_file;
135135

136-
int nr_paths;
137-
const char **paths;
138-
int *pathlens;
136+
struct pathspec pathspec;
139137
change_fn_t change;
140138
add_remove_fn_t add_remove;
141139
diff_format_fn_t format_callback;

revision.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
553553

554554
left_first = left_count < right_count;
555555
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;
561557

562558
/* Compute patch-ids for one side */
563559
for (p = list; p; p = p->next) {

tree-diff.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
100100
int pathlen;
101101
int never_interesting = -1;
102102

103-
if (!opt->nr_paths)
103+
if (!opt->pathspec.nr)
104104
return 1;
105105

106106
sha1 = tree_entry_extract(desc, &path, &mode);
107107

108108
pathlen = tree_entry_len(path, sha1);
109109

110-
for (i = 0; i < opt->nr_paths; i++) {
111-
const char *match = opt->paths[i];
112-
int matchlen = opt->pathlens[i];
110+
for (i = 0; i < opt->pathspec.nr; i++) {
111+
const char *match = opt->pathspec.raw[i];
112+
int matchlen = opt->pathspec.items[i].len;
113113
int m = -1; /* signals that we haven't called strncmp() */
114114

115115
if (baselen >= matchlen) {
@@ -289,7 +289,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
289289
if (DIFF_OPT_TST(opt, QUICK) &&
290290
DIFF_OPT_TST(opt, HAS_CHANGES))
291291
break;
292-
if (opt->nr_paths) {
292+
if (opt->pathspec.nr) {
293293
skip_uninteresting(t1, base, baselen, opt);
294294
skip_uninteresting(t2, base, baselen, opt);
295295
}
@@ -348,7 +348,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
348348
DIFF_OPT_SET(&diff_opts, RECURSIVE);
349349
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
350350
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
351-
diff_opts.single_follow = opt->paths[0];
351+
diff_opts.single_follow = opt->pathspec.raw[0];
352352
diff_opts.break_opt = opt->break_opt;
353353
paths[0] = NULL;
354354
diff_tree_setup_paths(paths, &diff_opts);
@@ -368,15 +368,15 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
368368
* diff_queued_diff, we will also use that as the path in
369369
* the future!
370370
*/
371-
if ((p->status == 'R' || p->status == 'C') && !strcmp(p->two->path, opt->paths[0])) {
371+
if ((p->status == 'R' || p->status == 'C') && !strcmp(p->two->path, opt->pathspec.raw[0])) {
372372
/* Switch the file-pairs around */
373373
q->queue[i] = choice;
374374
choice = p;
375375

376376
/* Update the path we use from now on.. */
377377
diff_tree_release_paths(opt);
378-
opt->paths[0] = xstrdup(p->one->path);
379-
diff_tree_setup_paths(opt->paths, opt);
378+
opt->pathspec.raw[0] = xstrdup(p->one->path);
379+
diff_tree_setup_paths(opt->pathspec.raw, opt);
380380

381381
/*
382382
* The caller expects us to return a set of vanilla
@@ -451,36 +451,12 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
451451
return retval;
452452
}
453453

454-
static int count_paths(const char **paths)
455-
{
456-
int i = 0;
457-
while (*paths++)
458-
i++;
459-
return i;
460-
}
461-
462454
void diff_tree_release_paths(struct diff_options *opt)
463455
{
464-
free(opt->pathlens);
456+
free_pathspec(&opt->pathspec);
465457
}
466458

467459
void diff_tree_setup_paths(const char **p, struct diff_options *opt)
468460
{
469-
opt->nr_paths = 0;
470-
opt->pathlens = NULL;
471-
opt->paths = NULL;
472-
473-
if (p) {
474-
int i;
475-
476-
opt->paths = p;
477-
opt->nr_paths = count_paths(p);
478-
if (opt->nr_paths == 0) {
479-
opt->pathlens = NULL;
480-
return;
481-
}
482-
opt->pathlens = xmalloc(opt->nr_paths * sizeof(int));
483-
for (i=0; i < opt->nr_paths; i++)
484-
opt->pathlens[i] = strlen(p[i]);
485-
}
461+
init_pathspec(&opt->pathspec, p);
486462
}

0 commit comments

Comments
 (0)