Merge branch 'sb/diff-color-moved-config-option-fixup'
authorJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2019 23:29:31 +0000 (15:29 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2019 23:29:31 +0000 (15:29 -0800)
Minor inconsistency fix.

* sb/diff-color-moved-config-option-fixup:
diff: align move detection error handling with other options

1  2 
diff.c
diff.h
diff --combined diff.c
index 15556c190d2e368fb2967a966263d1bcbfc09db2,d7d467b605d0f77b47f378c675eb5b61dbe2bc5f..f1e901a5fc3f4d4bd61fd1ce0ed69bb261424c15
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -291,7 -291,7 +291,7 @@@ static int parse_color_moved(const cha
                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;
                        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 +345,8 @@@ int git_diff_ui_config(const char *var
                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;
@@@ -1912,17 -1916,19 +1916,17 @@@ static int color_words_output_graph_pre
        }
  }
  
 -static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
 +static void fn_out_diff_words_aux(void *priv,
 +                                long minus_first, long minus_len,
 +                                long plus_first, long plus_len,
 +                                const char *func, long funclen)
  {
        struct diff_words_data *diff_words = priv;
        struct diff_words_style *style = diff_words->style;
 -      int minus_first, minus_len, plus_first, plus_len;
        const char *minus_begin, *minus_end, *plus_begin, *plus_end;
        struct diff_options *opt = diff_words->opt;
        const char *line_prefix;
  
 -      if (line[0] != '@' || parse_hunk_header(line, len,
 -                      &minus_first, &minus_len, &plus_first, &plus_len))
 -              return;
 -
        assert(opt);
        line_prefix = diff_line_prefix(opt);
  
@@@ -2072,8 -2078,8 +2076,8 @@@ static void diff_words_show(struct diff
        xpp.flags = 0;
        /* as only the hunk header will be parsed, we need a 0-context */
        xecfg.ctxlen = 0;
 -      if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
 -                        &xpp, &xecfg))
 +      if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, NULL,
 +                        diff_words, &xpp, &xecfg))
                die("unable to generate word diff");
        free(minus.ptr);
        free(plus.ptr);
@@@ -3128,15 -3134,6 +3132,15 @@@ static int is_conflict_marker(const cha
        return 1;
  }
  
 +static void checkdiff_consume_hunk(void *priv,
 +                                 long ob, long on, long nb, long nn,
 +                                 const char *func, long funclen)
 +
 +{
 +      struct checkdiff_t *data = priv;
 +      data->lineno = nb - 1;
 +}
 +
  static void checkdiff_consume(void *priv, char *line, unsigned long len)
  {
        struct checkdiff_t *data = priv;
                              data->o->file, set, reset, ws);
        } else if (line[0] == ' ') {
                data->lineno++;
 -      } else if (line[0] == '@') {
 -              char *plus = strchr(line, '+');
 -              if (plus)
 -                      data->lineno = strtol(plus, NULL, 10) - 1;
 -              else
 -                      die("invalid diff");
        }
  }
  
@@@ -3228,7 -3231,7 +3232,7 @@@ static void emit_binary_diff_body(struc
        }
  
        if (delta && delta_size < deflate_size) {
 -              char *s = xstrfmt("%lu", orig_size);
 +              char *s = xstrfmt("%"PRIuMAX , (uintmax_t)orig_size);
                emit_diff_symbol(o, DIFF_SYMBOL_BINARY_DIFF_HEADER_DELTA,
                                 s, strlen(s), 0);
                free(s);
@@@ -3313,14 -3316,14 +3317,14 @@@ void diff_set_mnemonic_prefix(struct di
                options->b_prefix = b;
  }
  
 -struct userdiff_driver *get_textconv(struct index_state *istate,
 +struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one)
  {
        if (!DIFF_FILE_VALID(one))
                return NULL;
  
 -      diff_filespec_load_driver(one, istate);
 -      return userdiff_get_textconv(one->driver);
 +      diff_filespec_load_driver(one, r->index);
 +      return userdiff_get_textconv(r, one->driver);
  }
  
  static void builtin_diff(const char *name_a,
        }
  
        if (o->flags.allow_textconv) {
 -              textconv_one = get_textconv(o->repo->index, one);
 -              textconv_two = get_textconv(o->repo->index, two);
 +              textconv_one = get_textconv(o->repo, one);
 +              textconv_two = get_textconv(o->repo, two);
        }
  
        /* Never use a non-valid filename anywhere if at all possible */
                        xecfg.ctxlen = strtoul(v, NULL, 10);
                if (o->word_diff)
                        init_diff_words_data(&ecbdata, o, one, two);
 -              if (xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
 -                                &xpp, &xecfg))
 +              if (xdi_diff_outf(&mf1, &mf2, NULL, fn_out_consume,
 +                                &ecbdata, &xpp, &xecfg))
                        die("unable to generate diff for %s", one->path);
                if (o->word_diff)
                        free_diff_words_data(&ecbdata);
@@@ -3638,8 -3641,8 +3642,8 @@@ static void builtin_diffstat(const cha
                xpp.anchors_nr = o->anchors_nr;
                xecfg.ctxlen = o->context;
                xecfg.interhunkctxlen = o->interhunkcontext;
 -              if (xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
 -                                &xpp, &xecfg))
 +              if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
 +                                diffstat_consume, diffstat, &xpp, &xecfg))
                        die("unable to generate diffstat for %s", one->path);
        }
  
@@@ -3687,8 -3690,7 +3691,8 @@@ static void builtin_checkdiff(const cha
                memset(&xecfg, 0, sizeof(xecfg));
                xecfg.ctxlen = 1; /* at least one context line */
                xpp.flags = 0;
 -              if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
 +              if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume_hunk,
 +                                checkdiff_consume, &data,
                                  &xpp, &xecfg))
                        die("unable to generate checkdiff for %s", one->path);
  
@@@ -5034,10 -5036,13 +5038,13 @@@ int diff_opt_parse(struct diff_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;
@@@ -5668,6 -5673,10 +5675,6 @@@ static void patch_id_consume(void *priv
        struct patch_id_t *data = priv;
        int new_len;
  
 -      /* Ignore line numbers when computing the SHA1 of the patch */
 -      if (starts_with(line, "@@ -"))
 -              return;
 -
        new_len = remove_space(line, len);
  
        git_SHA1_Update(data->ctx, line, new_len);
@@@ -5769,8 -5778,8 +5776,8 @@@ static int diff_get_patch_id(struct dif
                xpp.flags = 0;
                xecfg.ctxlen = 3;
                xecfg.flags = 0;
 -              if (xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
 -                                &xpp, &xecfg))
 +              if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
 +                                patch_id_consume, &data, &xpp, &xecfg))
                        return error("unable to generate patch-id diff for %s",
                                     p->one->path);
        }
@@@ -6434,7 -6443,7 +6441,7 @@@ int textconv_object(struct repository *
  
        df = alloc_filespec(path);
        fill_filespec(df, oid, oid_valid, mode);
 -      textconv = get_textconv(r->index, df);
 +      textconv = get_textconv(r, df);
        if (!textconv) {
                free_filespec(df);
                return 0;
diff --combined diff.h
index 412138ba085ccc3b998b704b2e6103db4313ed0d,9e8061ca29ab9010e591727cc1a09e0121a6ade6..b512d0477ac3a4a0338094a4d3b21770ecb57dd8
--- 1/diff.h
--- 2/diff.h
+++ b/diff.h
@@@ -225,7 -225,8 +225,8 @@@ struct diff_options 
  
        /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
        #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
-       int color_moved_ws_handling;
+       #define COLOR_MOVED_WS_ERROR (1<<0)
+       unsigned color_moved_ws_handling;
  
        struct repository *repo;
  };
@@@ -436,8 -437,7 +437,8 @@@ int diff_result_code(struct diff_option
  
  void diff_no_index(struct repository *, struct rev_info *, int, const char **);
  
 -int index_differs_from(const char *def, const struct diff_flags *flags,
 +int index_differs_from(struct repository *r, const char *def,
 +                     const struct diff_flags *flags,
                       int ita_invisible_in_index);
  
  /*
@@@ -461,7 -461,7 +462,7 @@@ size_t fill_textconv(struct repository 
   * and only if it has textconv enabled (otherwise return NULL). The result
   * can be passed to fill_textconv().
   */
 -struct userdiff_driver *get_textconv(struct index_state *istate,
 +struct userdiff_driver *get_textconv(struct repository *r,
                                     struct diff_filespec *one);
  
  /*