remove init_pathspec() in favor of parse_pathspec()
[gitweb.git] / builtin / add.c
index d039fc9ae0b9b2b44c5c85ad5345484658d5729c..a47aeb466211e8d40baa13db0b14aa76ce9037c7 100644 (file)
@@ -166,14 +166,16 @@ static void update_callback(struct diff_queue_struct *q,
        }
 }
 
-static void update_files_in_cache(const char *prefix, const char **pathspec,
+static void update_files_in_cache(const char *prefix,
+                                 const struct pathspec *pathspec,
                                  struct update_callback_data *data)
 {
        struct rev_info rev;
 
        init_revisions(&rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
-       init_pathspec(&rev.prune_data, pathspec);
+       if (pathspec)
+               copy_pathspec(&rev.prune_data, pathspec);
        rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = update_callback;
        rev.diffopt.format_callback_data = data;
@@ -181,7 +183,8 @@ static void update_files_in_cache(const char *prefix, const char **pathspec,
        run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
 }
 
-int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
+int add_files_to_cache(const char *prefix,
+                      const struct pathspec *pathspec, int flags)
 {
        struct update_callback_data data;
 
@@ -226,19 +229,18 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec,
        return seen;
 }
 
-static void refresh(int verbose, const char **pathspec)
+static void refresh(int verbose, const struct pathspec *pathspec)
 {
        char *seen;
-       int i, specs;
+       int i;
 
-       for (specs = 0; pathspec[specs];  specs++)
-               /* nothing */;
-       seen = xcalloc(specs, 1);
+       seen = xcalloc(pathspec->nr, 1);
        refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
                      pathspec, seen, _("Unstaged changes after refreshing the index:"));
-       for (i = 0; i < specs; i++) {
+       for (i = 0; i < pathspec->nr; i++) {
                if (!seen[i])
-                       die(_("pathspec '%s' did not match any files"), pathspec[i]);
+                       die(_("pathspec '%s' did not match any files"),
+                           pathspec->items[i].match);
        }
         free(seen);
 }
@@ -508,6 +510,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        if (add_new_files) {
                int baselen;
+               struct pathspec empty_pathspec;
 
                /* Set up the default git porcelain excludes */
                memset(&dir, 0, sizeof(dir));
@@ -516,15 +519,16 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        setup_standard_excludes(&dir);
                }
 
+               memset(&empty_pathspec, 0, sizeof(empty_pathspec));
                /* This picks up the paths that are not tracked */
-               baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec.raw);
+               baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
                if (pathspec.nr)
                        seen = prune_directory(&dir, pathspec.raw, baselen,
                                        implicit_dot ? WARN_IMPLICIT_DOT : 0);
        }
 
        if (refresh_only) {
-               refresh(verbose, pathspec.raw);
+               refresh(verbose, &pathspec);
                goto finish;
        }
        if (implicit_dot && prefix)
@@ -570,7 +574,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                memset(&pathspec, 0, sizeof(pathspec));
        }
        update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
-       update_files_in_cache(prefix, pathspec.raw, &update_data);
+       update_files_in_cache(prefix, &pathspec, &update_data);
 
        exit_status |= !!update_data.add_errors;
        if (add_new_files)