]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remove init_pathspec() in favor of parse_pathspec()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 14 Jul 2013 08:35:59 +0000 (15:35 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Jul 2013 17:56:09 +0000 (10:56 -0700)
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>
builtin/blame.c
builtin/log.c
builtin/ls-files.c
diff-lib.c
dir.c
merge-recursive.c
pathspec.c
pathspec.h
revision.c
tree-diff.c

index 5bd721d2b9d0bc80ffc68aae176cfdeac0fe7181..56e3d6b7b4718b05f655da97155afeec074d30a1 100644 (file)
@@ -408,7 +408,7 @@ static struct origin *find_origin(struct scoreboard *sb,
        paths[0] = origin->path;
        paths[1] = NULL;
 
-       init_pathspec(&diff_opts.pathspec, paths);
+       parse_pathspec(&diff_opts.pathspec, PATHSPEC_ALL_MAGIC, 0, "", paths);
        diff_setup_done(&diff_opts);
 
        if (is_null_sha1(origin->commit->object.sha1))
@@ -486,15 +486,12 @@ static struct origin *find_rename(struct scoreboard *sb,
        struct origin *porigin = NULL;
        struct diff_options diff_opts;
        int i;
-       const char *paths[2];
 
        diff_setup(&diff_opts);
        DIFF_OPT_SET(&diff_opts, RECURSIVE);
        diff_opts.detect_rename = DIFF_DETECT_RENAME;
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_opts.single_follow = origin->path;
-       paths[0] = NULL;
-       init_pathspec(&diff_opts.pathspec, paths);
        diff_setup_done(&diff_opts);
 
        if (is_null_sha1(origin->commit->object.sha1))
@@ -1064,7 +1061,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
                               int opt)
 {
        struct diff_options diff_opts;
-       const char *paths[1];
        int i, j;
        int retval;
        struct blame_list *blame_list;
@@ -1078,8 +1074,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
        DIFF_OPT_SET(&diff_opts, RECURSIVE);
        diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
-       paths[0] = NULL;
-       init_pathspec(&diff_opts.pathspec, paths);
        diff_setup_done(&diff_opts);
 
        /* Try "find copies harder" on new path if requested;
index e3222ed9f979e3140cbfc88ad2839c573c89bf06..873af6947671d2ed47d74569e5833ebd9fb68fdd 100644 (file)
@@ -503,7 +503,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        init_grep_defaults();
        git_config(git_log_config, NULL);
 
-       init_pathspec(&match_all, NULL);
+       memset(&match_all, 0, sizeof(match_all));
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.always_show_header = 1;
index c074e6fc7c1d8d3f5ca9c4f3995328f820747aaf..d3a0495f7d485134176c41e302b5a644a824dcfd 100644 (file)
@@ -315,13 +315,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
        }
 
        if (prefix) {
-               static const char *(matchbuf[2]);
-               matchbuf[0] = prefix;
-               matchbuf[1] = NULL;
-               init_pathspec(&pathspec, matchbuf);
-               pathspec.items[0].nowildcard_len = pathspec.items[0].len;
+               static const char *(matchbuf[1]);
+               matchbuf[0] = NULL;
+               parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+                              PATHSPEC_PREFER_CWD, prefix, matchbuf);
        } else
-               init_pathspec(&pathspec, NULL);
+               memset(&pathspec, 0, sizeof(pathspec));
        if (read_tree(tree, 1, &pathspec))
                die("unable to read tree entries %s", tree_name);
 
index d4e17f76620a46a659c7affcb3cd270f86b5a957..0a95763063494914e30b326a87d5e007765d8fcb 100644 (file)
@@ -501,7 +501,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
        struct rev_info revs;
 
        init_revisions(&revs, NULL);
-       init_pathspec(&revs.prune_data, opt->pathspec.raw);
+       copy_pathspec(&revs.prune_data, &opt->pathspec);
        revs.diffopt = *opt;
 
        if (diff_cache(&revs, tree_sha1, NULL, 1))
diff --git a/dir.c b/dir.c
index 019ad09b6e78ef9f2ee4ce057ffb826e48229bfb..959e6942c4577af666577311c762a4df6546abda 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1580,64 +1580,6 @@ int remove_path(const char *name)
        return 0;
 }
 
-static int pathspec_item_cmp(const void *a_, const void *b_)
-{
-       struct pathspec_item *a, *b;
-
-       a = (struct pathspec_item *)a_;
-       b = (struct pathspec_item *)b_;
-       return strcmp(a->match, b->match);
-}
-
-int init_pathspec(struct pathspec *pathspec, const char **paths)
-{
-       const char **p = paths;
-       int i;
-
-       memset(pathspec, 0, sizeof(*pathspec));
-       if (!p)
-               return 0;
-       while (*p)
-               p++;
-       pathspec->raw = paths;
-       pathspec->nr = p - paths;
-       if (!pathspec->nr)
-               return 0;
-
-       pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
-       for (i = 0; i < pathspec->nr; i++) {
-               struct pathspec_item *item = pathspec->items+i;
-               const char *path = paths[i];
-
-               item->match = path;
-               item->original = path;
-               item->len = strlen(path);
-               item->flags = 0;
-               if (limit_pathspec_to_literal()) {
-                       item->nowildcard_len = item->len;
-               } else {
-                       item->nowildcard_len = simple_length(path);
-                       if (item->nowildcard_len < item->len) {
-                               pathspec->has_wildcard = 1;
-                               if (path[item->nowildcard_len] == '*' &&
-                                   no_wildcard(path + item->nowildcard_len + 1))
-                                       item->flags |= PATHSPEC_ONESTAR;
-                       }
-               }
-       }
-
-       qsort(pathspec->items, pathspec->nr,
-             sizeof(struct pathspec_item), pathspec_item_cmp);
-
-       return 0;
-}
-
-void free_pathspec(struct pathspec *pathspec)
-{
-       free(pathspec->items);
-       pathspec->items = NULL;
-}
-
 int limit_pathspec_to_literal(void)
 {
        static int flag = -1;
index ea9dbd307c60a16f290b44964c386e566b6bc7e3..8395b9b08ac83f934b0e0c6fae4a9d83b0f0d6b2 100644 (file)
@@ -297,7 +297,7 @@ static int get_files_dirs(struct merge_options *o, struct tree *tree)
 {
        int n;
        struct pathspec match_all;
-       init_pathspec(&match_all, NULL);
+       memset(&match_all, 0, sizeof(match_all));
        if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
                return 0;
        n = o->current_file_set.nr + o->current_directory_set.nr;
index 2774bda47601664f9131d5b86afc6026139d0585..74f02036045753fc10b033dbf22c15f6b9db7bd3 100644 (file)
@@ -372,3 +372,9 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
        memcpy(dst->items, src->items,
               sizeof(struct pathspec_item) * dst->nr);
 }
+
+void free_pathspec(struct pathspec *pathspec)
+{
+       free(pathspec->items);
+       pathspec->items = NULL;
+}
index 02dded322f2428490344f2a124ec3964e12a1e9b..cadd46cca59b2788310f5f7a2f42f649c803257a 100644 (file)
@@ -53,7 +53,6 @@ struct pathspec {
 #define PATHSPEC_PREFIX_ORIGIN (1<<6)
 #define PATHSPEC_KEEP_ORDER (1<<7)
 
-extern int init_pathspec(struct pathspec *, const char **);
 extern void parse_pathspec(struct pathspec *pathspec,
                           unsigned magic_mask,
                           unsigned flags,
index c2d44b7365aac37316cd1b3b2691a187e166eb8b..001623a9213293387bddd51a25039bfd6353d98c 100644 (file)
@@ -1372,7 +1372,7 @@ static void prepare_show_merge(struct rev_info *revs)
                        i++;
        }
        free_pathspec(&revs->prune_data);
-       init_pathspec(&revs->prune_data, prune);
+       parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
        revs->limited = 1;
 }
 
index f4c92f6e200e592ddf8971e5e65566f4ea81d910..e1145c60e7a82e2c6422494603fbb4e01f865cf4 100644 (file)
@@ -195,7 +195,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        struct diff_options diff_opts;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_filepair *choice;
-       const char *paths[1];
        int i;
 
        /*
@@ -228,8 +227,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        diff_opts.single_follow = opt->pathspec.raw[0];
        diff_opts.break_opt = opt->break_opt;
        diff_opts.rename_score = opt->rename_score;
-       paths[0] = NULL;
-       init_pathspec(&diff_opts.pathspec, paths);
        diff_setup_done(&diff_opts);
        diff_tree(t1, t2, base, &diff_opts);
        diffcore_std(&diff_opts);
@@ -247,14 +244,17 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
                 */
                if ((p->status == 'R' || p->status == 'C') &&
                    !strcmp(p->two->path, opt->pathspec.raw[0])) {
+                       const char *path[2];
+
                        /* Switch the file-pairs around */
                        q->queue[i] = choice;
                        choice = p;
 
                        /* Update the path we use from now on.. */
+                       path[0] = p->one->path;
+                       path[1] = NULL;
                        free_pathspec(&opt->pathspec);
-                       opt->pathspec.raw[0] = xstrdup(p->one->path);
-                       init_pathspec(&opt->pathspec, opt->pathspec.raw);
+                       parse_pathspec(&opt->pathspec, PATHSPEC_ALL_MAGIC, 0, "", path);
 
                        /*
                         * The caller expects us to return a set of vanilla