]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diff.c
diff: align move detection error handling with other options
[thirdparty/git.git] / diff.c
diff --git a/diff.c b/diff.c
index e82b6341ee539882a7f0a21322ab304070a47a23..d7d467b605d0f77b47f378c675eb5b61dbe2bc5f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -291,7 +291,7 @@ static int parse_color_moved(const char *arg)
                return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed-zebra', 'plain'"));
 }
 
-static int parse_color_moved_ws(const char *arg)
+static unsigned parse_color_moved_ws(const char *arg)
 {
        int ret = 0;
        struct string_list l = STRING_LIST_INIT_DUP;
@@ -312,15 +312,19 @@ static int parse_color_moved_ws(const char *arg)
                        ret |= XDF_IGNORE_WHITESPACE;
                else if (!strcmp(sb.buf, "allow-indentation-change"))
                        ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
-               else
-                       error(_("ignoring unknown color-moved-ws mode '%s'"), sb.buf);
+               else {
+                       ret |= COLOR_MOVED_WS_ERROR;
+                       error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), sb.buf);
+               }
 
                strbuf_release(&sb);
        }
 
        if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&
-           (ret & XDF_WHITESPACE_FLAGS))
-               die(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
+           (ret & XDF_WHITESPACE_FLAGS)) {
+               error(_("color-moved-ws: allow-indentation-change cannot be combined with other white space modes"));
+               ret |= COLOR_MOVED_WS_ERROR;
+       }
 
        string_list_clear(&l, 0);
 
@@ -341,8 +345,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (!strcmp(var, "diff.colormovedws")) {
-               int cm = parse_color_moved_ws(value);
-               if (cm < 0)
+               unsigned cm = parse_color_moved_ws(value);
+               if (cm & COLOR_MOVED_WS_ERROR)
                        return -1;
                diff_color_moved_ws_default = cm;
                return 0;
@@ -4302,12 +4306,12 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
 static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
 {
        /* Strip the prefix but do not molest /dev/null and absolute paths */
-       if (*namep && **namep != '/') {
+       if (*namep && !is_absolute_path(*namep)) {
                *namep += prefix_length;
                if (**namep == '/')
                        ++*namep;
        }
-       if (*otherp && **otherp != '/') {
+       if (*otherp && !is_absolute_path(*otherp)) {
                *otherp += prefix_length;
                if (**otherp == '/')
                        ++*otherp;
@@ -5032,10 +5036,13 @@ int diff_opt_parse(struct diff_options *options,
        else if (skip_prefix(arg, "--color-moved=", &arg)) {
                int cm = parse_color_moved(arg);
                if (cm < 0)
-                       die("bad --color-moved argument: %s", arg);
+                       return error("bad --color-moved argument: %s", arg);
                options->color_moved = cm;
        } else if (skip_prefix(arg, "--color-moved-ws=", &arg)) {
-               options->color_moved_ws_handling = parse_color_moved_ws(arg);
+               unsigned cm = parse_color_moved_ws(arg);
+               if (cm & COLOR_MOVED_WS_ERROR)
+                       return -1;
+               options->color_moved_ws_handling = cm;
        } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;