refactor skip_prefix to return a boolean
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index f66716fab4b477c58434126b4aaa4b4372ce163a..77c5eb4529909b0cd0a527787242efa1322bfe8f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -52,23 +52,23 @@ static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL,       /* FUNCINFO */
 };
 
-static int parse_diff_color_slot(const char *var, int ofs)
+static int parse_diff_color_slot(const char *var)
 {
-       if (!strcasecmp(var+ofs, "plain"))
+       if (!strcasecmp(var, "plain"))
                return DIFF_PLAIN;
-       if (!strcasecmp(var+ofs, "meta"))
+       if (!strcasecmp(var, "meta"))
                return DIFF_METAINFO;
-       if (!strcasecmp(var+ofs, "frag"))
+       if (!strcasecmp(var, "frag"))
                return DIFF_FRAGINFO;
-       if (!strcasecmp(var+ofs, "old"))
+       if (!strcasecmp(var, "old"))
                return DIFF_FILE_OLD;
-       if (!strcasecmp(var+ofs, "new"))
+       if (!strcasecmp(var, "new"))
                return DIFF_FILE_NEW;
-       if (!strcasecmp(var+ofs, "commit"))
+       if (!strcasecmp(var, "commit"))
                return DIFF_COMMIT;
-       if (!strcasecmp(var+ofs, "whitespace"))
+       if (!strcasecmp(var, "whitespace"))
                return DIFF_WHITESPACE;
-       if (!strcasecmp(var+ofs, "func"))
+       if (!strcasecmp(var, "func"))
                return DIFF_FUNCINFO;
        return -1;
 }
@@ -240,7 +240,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
                return -1;
 
        if (starts_with(var, "diff.color.") || starts_with(var, "color.diff.")) {
-               int slot = parse_diff_color_slot(var, 11);
+               int slot = parse_diff_color_slot(var + 11);
                if (slot < 0)
                        return 0;
                if (!value)
@@ -1361,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) {
@@ -3320,6 +3320,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)