configure.ac: use $LIBS not $CFLAGS when testing -lpthread
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index 539997fc6a679b2d85479a4d8f12f864d92b6c7c..3f1f08f9fd28173e10440c8436d57c14215c342c 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -16,6 +16,7 @@
 #include "submodule.h"
 #include "ll-merge.h"
 #include "string-list.h"
+#include "argv-array.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -1360,7 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
                                          const char *name_b)
 {
        struct diffstat_file *x;
-       x = xcalloc(sizeof (*x), 1);
+       x = xcalloc(1, sizeof(*x));
        ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
        diffstat->files[diffstat->nr++] = x;
        if (name_b) {
@@ -1461,20 +1462,12 @@ int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
         * but nothing about added/removed lines? Is this a bug in Git?").
         */
        if (insertions || deletions == 0) {
-               /*
-                * TRANSLATORS: "+" in (+) is a line addition marker;
-                * do not translate it.
-                */
                strbuf_addf(&sb,
                            (insertions == 1) ? ", %d insertion(+)" : ", %d insertions(+)",
                            insertions);
        }
 
        if (deletions || insertions == 0) {
-               /*
-                * TRANSLATORS: "-" in (-) is a line removal marker;
-                * do not translate it.
-                */
                strbuf_addf(&sb,
                            (deletions == 1) ? ", %d deletion(-)" : ", %d deletions(-)",
                            deletions);
@@ -2902,9 +2895,8 @@ static void run_external_diff(const char *pgm,
                              int complete_rewrite,
                              struct diff_options *o)
 {
-       const char *spawn_arg[10];
+       struct argv_array argv = ARGV_ARRAY_INIT;
        int retval;
-       const char **arg = &spawn_arg[0];
        struct diff_queue_struct *q = &diff_queued_diff;
        const char *env[3] = { NULL };
        char env_counter[50];
@@ -2915,23 +2907,22 @@ static void run_external_diff(const char *pgm,
                const char *othername = (other ? other : name);
                temp_one = prepare_temp_file(name, one);
                temp_two = prepare_temp_file(othername, two);
-               *arg++ = pgm;
-               *arg++ = name;
-               *arg++ = temp_one->name;
-               *arg++ = temp_one->hex;
-               *arg++ = temp_one->mode;
-               *arg++ = temp_two->name;
-               *arg++ = temp_two->hex;
-               *arg++ = temp_two->mode;
+               argv_array_push(&argv, pgm);
+               argv_array_push(&argv, name);
+               argv_array_push(&argv, temp_one->name);
+               argv_array_push(&argv, temp_one->hex);
+               argv_array_push(&argv, temp_one->mode);
+               argv_array_push(&argv, temp_two->name);
+               argv_array_push(&argv, temp_two->hex);
+               argv_array_push(&argv, temp_two->mode);
                if (other) {
-                       *arg++ = other;
-                       *arg++ = xfrm_msg;
+                       argv_array_push(&argv, other);
+                       argv_array_push(&argv, xfrm_msg);
                }
        } else {
-               *arg++ = pgm;
-               *arg++ = name;
+               argv_array_push(&argv, pgm);
+               argv_array_push(&argv, name);
        }
-       *arg = NULL;
        fflush(NULL);
 
        env[0] = env_counter;
@@ -2940,8 +2931,9 @@ static void run_external_diff(const char *pgm,
        env[1] = env_total;
        snprintf(env_total, sizeof(env_total), "GIT_DIFF_PATH_TOTAL=%d", q->nr);
 
-       retval = run_command_v_opt_cd_env(spawn_arg, RUN_USING_SHELL, NULL, env);
+       retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env);
        remove_tempfile();
+       argv_array_clear(&argv);
        if (retval) {
                fprintf(stderr, "external diff died, stopping at %s.\n", name);
                exit(1);
@@ -3333,6 +3325,9 @@ void diff_setup_done(struct diff_options *options)
        }
 
        options->diff_path_counter = 0;
+
+       if (DIFF_OPT_TST(options, FOLLOW_RENAMES) && options->pathspec.nr != 1)
+               die(_("--follow requires exactly one pathspec"));
 }
 
 static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)