remove init_pathspec() in favor of parse_pathspec()

While at there, move free_pathspec() to pathspec.c 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 Jul 14, 2013 at 15:35 UTC 9a0872744315da67db3c81eb9270751e31fcc8f5
10 files changed +21 -81
builtin/blame.c
+1 -7
@@ -408,7 +408,7 @@ static struct origin *find_origin(struct scoreboard *sb,
408 paths[0] = origin->path;
409 paths[1] = NULL;
410
411 - init_pathspec(&diff_opts.pathspec, paths);
411 + parse_pathspec(&diff_opts.pathspec, PATHSPEC_ALL_MAGIC, 0, "", paths);
412 diff_setup_done(&diff_opts);
413
414 if (is_null_sha1(origin->commit->object.sha1))
@@ -486,15 +486,12 @@ static struct origin *find_rename(struct scoreboard *sb,
486 struct origin *porigin = NULL;
487 struct diff_options diff_opts;
488 int i;
489 - const char *paths[2];
489
490 diff_setup(&diff_opts);
491 DIFF_OPT_SET(&diff_opts, RECURSIVE);
492 diff_opts.detect_rename = DIFF_DETECT_RENAME;
493 diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
494 diff_opts.single_follow = origin->path;
496 - paths[0] = NULL;
497 - init_pathspec(&diff_opts.pathspec, paths);
495 diff_setup_done(&diff_opts);
496
497 if (is_null_sha1(origin->commit->object.sha1))
@@ -1064,7 +1061,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
1061 int opt)
1062 {
1063 struct diff_options diff_opts;
1067 - const char *paths[1];
1064 int i, j;
1065 int retval;
1066 struct blame_list *blame_list;
@@ -1078,8 +1074,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
1074 DIFF_OPT_SET(&diff_opts, RECURSIVE);
1075 diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1076
1081 - paths[0] = NULL;
1082 - init_pathspec(&diff_opts.pathspec, paths);
1077 diff_setup_done(&diff_opts);
1078
1079 /* Try "find copies harder" on new path if requested;
builtin/log.c
+1 -1
@@ -503,7 +503,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
503 init_grep_defaults();
504 git_config(git_log_config, NULL);
505
506 - init_pathspec(&match_all, NULL);
506 + memset(&match_all, 0, sizeof(match_all));
507 init_revisions(&rev, prefix);
508 rev.diff = 1;
509 rev.always_show_header = 1;
builtin/ls-files.c
+5 -6
@@ -315,13 +315,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
315 }
316
317 if (prefix) {
318 - static const char *(matchbuf[2]);
319 - matchbuf[0] = prefix;
320 - matchbuf[1] = NULL;
321 - init_pathspec(&pathspec, matchbuf);
322 - pathspec.items[0].nowildcard_len = pathspec.items[0].len;
318 + static const char *(matchbuf[1]);
319 + matchbuf[0] = NULL;
320 + parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
321 + PATHSPEC_PREFER_CWD, prefix, matchbuf);
322 } else
324 - init_pathspec(&pathspec, NULL);
323 + memset(&pathspec, 0, sizeof(pathspec));
324 if (read_tree(tree, 1, &pathspec))
325 die("unable to read tree entries %s", tree_name);
326
diff-lib.c
+1 -1
@@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
501 struct rev_info revs;
502
503 init_revisions(&revs, NULL);
504 - init_pathspec(&revs.prune_data, opt->pathspec.raw);
504 + copy_pathspec(&revs.prune_data, &opt->pathspec);
505 revs.diffopt = *opt;
506
507 if (diff_cache(&revs, tree_sha1, NULL, 1))
dir.c
-58
@@ -1580,64 +1580,6 @@ int remove_path(const char *name)
1580 return 0;
1581 }
1582
1583 -static int pathspec_item_cmp(const void *a_, const void *b_)
1584 -{
1585 - struct pathspec_item *a, *b;
1586 -
1587 - a = (struct pathspec_item *)a_;
1588 - b = (struct pathspec_item *)b_;
1589 - return strcmp(a->match, b->match);
1590 -}
1591 -
1592 -int init_pathspec(struct pathspec *pathspec, const char **paths)
1593 -{
1594 - const char **p = paths;
1595 - int i;
1596 -
1597 - memset(pathspec, 0, sizeof(*pathspec));
1598 - if (!p)
1599 - return 0;
1600 - while (*p)
1601 - p++;
1602 - pathspec->raw = paths;
1603 - pathspec->nr = p - paths;
1604 - if (!pathspec->nr)
1605 - return 0;
1606 -
1607 - pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
1608 - for (i = 0; i < pathspec->nr; i++) {
1609 - struct pathspec_item *item = pathspec->items+i;
1610 - const char *path = paths[i];
1611 -
1612 - item->match = path;
1613 - item->original = path;
1614 - item->len = strlen(path);
1615 - item->flags = 0;
1616 - if (limit_pathspec_to_literal()) {
1617 - item->nowildcard_len = item->len;
1618 - } else {
1619 - item->nowildcard_len = simple_length(path);
1620 - if (item->nowildcard_len < item->len) {
1621 - pathspec->has_wildcard = 1;
1622 - if (path[item->nowildcard_len] == '*' &&
1623 - no_wildcard(path + item->nowildcard_len + 1))
1624 - item->flags |= PATHSPEC_ONESTAR;
1625 - }
1626 - }
1627 - }
1628 -
1629 - qsort(pathspec->items, pathspec->nr,
1630 - sizeof(struct pathspec_item), pathspec_item_cmp);
1631 -
1632 - return 0;
1633 -}
1634 -
1635 -void free_pathspec(struct pathspec *pathspec)
1636 -{
1637 - free(pathspec->items);
1638 - pathspec->items = NULL;
1639 -}
1640 -
1583 int limit_pathspec_to_literal(void)
1584 {
1585 static int flag = -1;
merge-recursive.c
+1 -1
@@ -297,7 +297,7 @@ static int get_files_dirs(struct merge_options *o, struct tree *tree)
297 {
298 int n;
299 struct pathspec match_all;
300 - init_pathspec(&match_all, NULL);
300 + memset(&match_all, 0, sizeof(match_all));
301 if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
302 return 0;
303 n = o->current_file_set.nr + o->current_directory_set.nr;
pathspec.c
+6
@@ -372,3 +372,9 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
372 memcpy(dst->items, src->items,
373 sizeof(struct pathspec_item) * dst->nr);
374 }
375 +
376 +void free_pathspec(struct pathspec *pathspec)
377 +{
378 + free(pathspec->items);
379 + pathspec->items = NULL;
380 +}
pathspec.h
-1
@@ -53,7 +53,6 @@ struct pathspec {
53 #define PATHSPEC_PREFIX_ORIGIN (1<<6)
54 #define PATHSPEC_KEEP_ORDER (1<<7)
55
56 -extern int init_pathspec(struct pathspec *, const char **);
56 extern void parse_pathspec(struct pathspec *pathspec,
57 unsigned magic_mask,
58 unsigned flags,
revision.c
+1 -1
@@ -1372,7 +1372,7 @@ static void prepare_show_merge(struct rev_info *revs)
1372 i++;
1373 }
1374 free_pathspec(&revs->prune_data);
1375 - init_pathspec(&revs->prune_data, prune);
1375 + parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
1376 revs->limited = 1;
1377 }
1378
tree-diff.c
+5 -5
@@ -195,7 +195,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
195 struct diff_options diff_opts;
196 struct diff_queue_struct *q = &diff_queued_diff;
197 struct diff_filepair *choice;
198 - const char *paths[1];
198 int i;
199
200 /*
@@ -228,8 +227,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
227 diff_opts.single_follow = opt->pathspec.raw[0];
228 diff_opts.break_opt = opt->break_opt;
229 diff_opts.rename_score = opt->rename_score;
231 - paths[0] = NULL;
232 - init_pathspec(&diff_opts.pathspec, paths);
230 diff_setup_done(&diff_opts);
231 diff_tree(t1, t2, base, &diff_opts);
232 diffcore_std(&diff_opts);
@@ -247,14 +244,17 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
244 */
245 if ((p->status == 'R' || p->status == 'C') &&
246 !strcmp(p->two->path, opt->pathspec.raw[0])) {
247 + const char *path[2];
248 +
249 /* Switch the file-pairs around */
250 q->queue[i] = choice;
251 choice = p;
252
253 /* Update the path we use from now on.. */
254 + path[0] = p->one->path;
255 + path[1] = NULL;
256 free_pathspec(&opt->pathspec);
256 - opt->pathspec.raw[0] = xstrdup(p->one->path);
257 - init_pathspec(&opt->pathspec, opt->pathspec.raw);
257 + parse_pathspec(&opt->pathspec, PATHSPEC_ALL_MAGIC, 0, "", path);
258
259 /*
260 * The caller expects us to return a set of vanilla