remove diff_tree_{setup,release}_paths
[gitweb.git] / tree-diff.c
index ba01563a0241041cb401cfb03495e6067847248e..f4c92f6e200e592ddf8971e5e65566f4ea81d910 100644 (file)
@@ -138,7 +138,6 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
 
        /* Enable recursion indefinitely */
        opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
-       opt->pathspec.max_depth = -1;
 
        strbuf_init(&base, PATH_MAX);
        strbuf_add(&base, base_str, baselen);
@@ -199,6 +198,25 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        const char *paths[1];
        int i;
 
+       /*
+        * follow-rename code is very specific, we need exactly one
+        * path. Magic that matches more than one path is not
+        * supported.
+        */
+       GUARD_PATHSPEC(&opt->pathspec, PATHSPEC_FROMTOP);
+#if 0
+       /*
+        * We should reject wildcards as well. Unfortunately we
+        * haven't got a reliable way to detect that 'foo\*bar' in
+        * fact has no wildcards. nowildcard_len is merely a hint for
+        * optimization. Let it slip for now until wildmatch is taught
+        * about dry-run mode and returns wildcard info.
+        */
+       if (opt->pathspec.has_wildcard)
+               die("BUG:%s:%d: wildcards are not supported",
+                   __FILE__, __LINE__);
+#endif
+
        /* Remove the file creation entry from the diff queue, and remember it */
        choice = q->queue[0];
        q->nr = 0;
@@ -211,11 +229,11 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
        diff_opts.break_opt = opt->break_opt;
        diff_opts.rename_score = opt->rename_score;
        paths[0] = NULL;
-       diff_tree_setup_paths(paths, &diff_opts);
+       init_pathspec(&diff_opts.pathspec, paths);
        diff_setup_done(&diff_opts);
        diff_tree(t1, t2, base, &diff_opts);
        diffcore_std(&diff_opts);
-       diff_tree_release_paths(&diff_opts);
+       free_pathspec(&diff_opts.pathspec);
 
        /* Go through the new set of filepairing, and see if we find a more interesting one */
        opt->found_follow = 0;
@@ -234,9 +252,9 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
                        choice = p;
 
                        /* Update the path we use from now on.. */
-                       diff_tree_release_paths(opt);
+                       free_pathspec(&opt->pathspec);
                        opt->pathspec.raw[0] = xstrdup(p->one->path);
-                       diff_tree_setup_paths(opt->pathspec.raw, opt);
+                       init_pathspec(&opt->pathspec, opt->pathspec.raw);
 
                        /*
                         * The caller expects us to return a set of vanilla
@@ -310,13 +328,3 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
        free(tree);
        return retval;
 }
-
-void diff_tree_release_paths(struct diff_options *opt)
-{
-       free_pathspec(&opt->pathspec);
-}
-
-void diff_tree_setup_paths(const char **p, struct diff_options *opt)
-{
-       init_pathspec(&opt->pathspec, p);
-}