Merge branch 'es/diff-color-moved-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 15 Aug 2018 22:08:22 +0000 (15:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Aug 2018 22:08:22 +0000 (15:08 -0700)
One of the "diff --color-moved" mode "dimmed_zebra" that was named
in an unusual way has been deprecated and replaced by
"dimmed-zebra".

* es/diff-color-moved-fix:
diff: --color-moved: rename "dimmed_zebra" to "dimmed-zebra"

1  2 
Documentation/diff-options.txt
diff.c
t/t4015-diff-whitespace.sh
index f394608b42c268f0f187dafabe50b718fde2a8bf,cbc05e8a95a670319ae2b54f42fddc23acf670d3..0378cd574eb01069baba14221d511f580565c0eb
@@@ -64,7 -64,7 +64,7 @@@ ifndef::git-format-patch[
  endif::git-format-patch[]
  
  --indent-heuristic::
 -      Enable the heuristic that shift diff hunk boundaries to make patches
 +      Enable the heuristic that shifts diff hunk boundaries to make patches
        easier to read. This is the default.
  
  --no-indent-heuristic::
@@@ -106,7 -106,7 +106,7 @@@ diff" algorithm internally
        low-occurrence common elements".
  --
  +
 -For instance, if you configured diff.algorithm variable to a
 +For instance, if you configured the `diff.algorithm` variable to a
  non-default value and want to use the default one, then you
  have to use `--diff-algorithm=default` option.
  
  These parameters can also be set individually with `--stat-width=<width>`,
  `--stat-name-width=<name-width>` and `--stat-count=<count>`.
  
 +--compact-summary::
 +      Output a condensed summary of extended header information such
 +      as file creations or deletions ("new" or "gone", optionally "+l"
 +      if it's a symlink) and mode changes ("+x" or "-x" for adding
 +      or removing executable bit respectively) in diffstat. The
 +      information is put between the filename part and the graph
 +      part. Implies `--stat`.
 +
  --numstat::
        Similar to `--stat`, but shows number of added and
        deleted lines in decimal notation and pathname without
@@@ -276,47 -268,19 +276,48 @@@ plain:
        that are added somewhere else in the diff. This mode picks up any
        moved line, but it is not very useful in a review to determine
        if a block of code was moved without permutation.
 -zebra::
 +blocks::
        Blocks of moved text of at least 20 alphanumeric characters
        are detected greedily. The detected blocks are
 -      painted using either the 'color.diff.{old,new}Moved' color or
 +      painted using either the 'color.diff.{old,new}Moved' color.
 +      Adjacent blocks cannot be told apart.
 +zebra::
 +      Blocks of moved text are detected as in 'blocks' mode. The blocks
 +      are painted using either the 'color.diff.{old,new}Moved' color or
        'color.diff.{old,new}MovedAlternative'. The change between
        the two colors indicates that a new block was detected.
- dimmed_zebra::
+ dimmed-zebra::
        Similar to 'zebra', but additional dimming of uninteresting parts
        of moved code is performed. The bordering lines of two adjacent
        blocks are considered interesting, the rest is uninteresting.
+       `dimmed_zebra` is a deprecated synonym.
  --
  
 +--color-moved-ws=<modes>::
 +      This configures how white spaces are ignored when performing the
 +      move detection for `--color-moved`.
 +ifdef::git-diff[]
 +      It can be set by the `diff.colorMovedWS` configuration setting.
 +endif::git-diff[]
 +      These modes can be given as a comma separated list:
 ++
 +--
 +ignore-space-at-eol::
 +      Ignore changes in whitespace at EOL.
 +ignore-space-change::
 +      Ignore changes in amount of whitespace.  This ignores whitespace
 +      at line end, and considers all other sequences of one or
 +      more whitespace characters to be equivalent.
 +ignore-all-space::
 +      Ignore whitespace when comparing lines. This ignores differences
 +      even if one line has whitespace where the other line has none.
 +allow-indentation-change::
 +      Initially ignore any white spaces in the move detection, then
 +      group the moved code blocks only into a block if the change in
 +      whitespace is the same per line. This is incompatible with the
 +      other modes.
 +--
 +
  --word-diff[=<mode>]::
        Show a word diff, using the <mode> to delimit changed words.
        By default, words are delimited by whitespace; see
@@@ -379,7 -343,7 +380,7 @@@ ifndef::git-format-patch[
        Warn if changes introduce conflict markers or whitespace errors.
        What are considered whitespace errors is controlled by `core.whitespace`
        configuration.  By default, trailing whitespaces (including
 -      lines that solely consist of whitespaces) and a space character
 +      lines that consist solely of whitespaces) and a space character
        that is immediately followed by a tab character inside the
        initial indent of the line are considered whitespace errors.
        Exits with non-zero status if problems are found. Not compatible
        this option is not given, and the configuration variable
        `diff.wsErrorHighlight` is not set, only whitespace errors in
        `new` lines are highlighted. The whitespace errors are colored
 -      whith `color.diff.whitespace`.
 +      with `color.diff.whitespace`.
  
  endif::git-format-patch[]
  
@@@ -545,15 -509,6 +546,15 @@@ occurrences of that string did not chan
  See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
  information.
  
 +--find-object=<object-id>::
 +      Look for differences that change the number of occurrences of
 +      the specified object. Similar to `-S`, just the argument is different
 +      in that it doesn't search for a specific string but for a specific
 +      object id.
 ++
 +The object can be a blob or a submodule commit. It implies the `-t` option in
 +`git-log` to also find trees.
 +
  --pickaxe-all::
        When `-S` or `-G` finds a change, show all the changes in that
        changeset, not just the files that contain the change
  --pickaxe-regex::
        Treat the <string> given to `-S` as an extended POSIX regular
        expression to match.
 +
  endif::git-format-patch[]
  
  -O<orderfile>::
@@@ -597,7 -551,7 +598,7 @@@ the normal order
  --
  +
  Patterns have the same syntax and semantics as patterns used for
 -fnmantch(3) without the FNM_PATHNAME flag, except a pathname also
 +fnmatch(3) without the FNM_PATHNAME flag, except a pathname also
  matches a pattern if removing any number of the final pathname
  components matches the pattern.  For example, the pattern "`foo*bar`"
  matches "`fooasdfbar`" and "`foo/bar/baz/asdf`" but not "`foobarx`".
@@@ -621,7 -575,7 +622,7 @@@ endif::git-format-patch[
        Treat all files as text.
  
  --ignore-cr-at-eol::
 -      Ignore carrige-return at the end of line when doing a comparison.
 +      Ignore carriage-return at the end of line when doing a comparison.
  
  --ignore-space-at-eol::
        Ignore changes in whitespace at EOL.
diff --combined diff.c
index 04d044bbb67b77a9992a499d4f7728bb85cfe94f,717100780d9a9ea37f3d619fc74594e023ac45f9..0746d59fe6d04287e0a4053b4bb0eeda5fd26778
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -13,7 -13,6 +13,7 @@@
  #include "attr.h"
  #include "run-command.h"
  #include "utf8.h"
 +#include "object-store.h"
  #include "userdiff.h"
  #include "submodule-config.h"
  #include "submodule.h"
@@@ -23,7 -22,6 +23,7 @@@
  #include "argv-array.h"
  #include "graph.h"
  #include "packfile.h"
 +#include "help.h"
  
  #ifdef NO_FAST_WORKING_DIRECTORY
  #define FAST_WORKING_DIRECTORY 0
@@@ -37,7 -35,6 +37,7 @@@ static int diff_rename_limit_default = 
  static int diff_suppress_blank_empty;
  static int diff_use_color_default = -1;
  static int diff_color_moved_default;
 +static int diff_color_moved_ws_default;
  static int diff_context_default = 3;
  static int diff_interhunk_context_default;
  static const char *diff_word_regex_cfg;
@@@ -72,37 -69,46 +72,37 @@@ static char diff_colors[][COLOR_MAXLEN
        GIT_COLOR_FAINT_ITALIC, /* NEW_MOVED_ALTERNATIVE_DIM */
  };
  
 +static const char *color_diff_slots[] = {
 +      [DIFF_CONTEXT]                = "context",
 +      [DIFF_METAINFO]               = "meta",
 +      [DIFF_FRAGINFO]               = "frag",
 +      [DIFF_FILE_OLD]               = "old",
 +      [DIFF_FILE_NEW]               = "new",
 +      [DIFF_COMMIT]                 = "commit",
 +      [DIFF_WHITESPACE]             = "whitespace",
 +      [DIFF_FUNCINFO]               = "func",
 +      [DIFF_FILE_OLD_MOVED]         = "oldMoved",
 +      [DIFF_FILE_OLD_MOVED_ALT]     = "oldMovedAlternative",
 +      [DIFF_FILE_OLD_MOVED_DIM]     = "oldMovedDimmed",
 +      [DIFF_FILE_OLD_MOVED_ALT_DIM] = "oldMovedAlternativeDimmed",
 +      [DIFF_FILE_NEW_MOVED]         = "newMoved",
 +      [DIFF_FILE_NEW_MOVED_ALT]     = "newMovedAlternative",
 +      [DIFF_FILE_NEW_MOVED_DIM]     = "newMovedDimmed",
 +      [DIFF_FILE_NEW_MOVED_ALT_DIM] = "newMovedAlternativeDimmed",
 +};
 +
  static NORETURN void die_want_option(const char *option_name)
  {
        die(_("option '%s' requires a value"), option_name);
  }
  
 +define_list_config_array_extra(color_diff_slots, {"plain"});
 +
  static int parse_diff_color_slot(const char *var)
  {
 -      if (!strcasecmp(var, "context") || !strcasecmp(var, "plain"))
 +      if (!strcasecmp(var, "plain"))
                return DIFF_CONTEXT;
 -      if (!strcasecmp(var, "meta"))
 -              return DIFF_METAINFO;
 -      if (!strcasecmp(var, "frag"))
 -              return DIFF_FRAGINFO;
 -      if (!strcasecmp(var, "old"))
 -              return DIFF_FILE_OLD;
 -      if (!strcasecmp(var, "new"))
 -              return DIFF_FILE_NEW;
 -      if (!strcasecmp(var, "commit"))
 -              return DIFF_COMMIT;
 -      if (!strcasecmp(var, "whitespace"))
 -              return DIFF_WHITESPACE;
 -      if (!strcasecmp(var, "func"))
 -              return DIFF_FUNCINFO;
 -      if (!strcasecmp(var, "oldmoved"))
 -              return DIFF_FILE_OLD_MOVED;
 -      if (!strcasecmp(var, "oldmovedalternative"))
 -              return DIFF_FILE_OLD_MOVED_ALT;
 -      if (!strcasecmp(var, "oldmoveddimmed"))
 -              return DIFF_FILE_OLD_MOVED_DIM;
 -      if (!strcasecmp(var, "oldmovedalternativedimmed"))
 -              return DIFF_FILE_OLD_MOVED_ALT_DIM;
 -      if (!strcasecmp(var, "newmoved"))
 -              return DIFF_FILE_NEW_MOVED;
 -      if (!strcasecmp(var, "newmovedalternative"))
 -              return DIFF_FILE_NEW_MOVED_ALT;
 -      if (!strcasecmp(var, "newmoveddimmed"))
 -              return DIFF_FILE_NEW_MOVED_DIM;
 -      if (!strcasecmp(var, "newmovedalternativedimmed"))
 -              return DIFF_FILE_NEW_MOVED_ALT_DIM;
 -      return -1;
 +      return LOOKUP_CONFIG(color_diff_slots, var);
  }
  
  static int parse_dirstat_params(struct diff_options *options, const char *params_string,
@@@ -171,7 -177,7 +171,7 @@@ static int parse_submodule_params(struc
        return 0;
  }
  
 -static int git_config_rename(const char *var, const char *value)
 +int git_config_rename(const char *var, const char *value)
  {
        if (!value)
                return DIFF_DETECT_RENAME;
@@@ -265,52 -271,16 +265,54 @@@ static int parse_color_moved(const cha
                return COLOR_MOVED_NO;
        else if (!strcmp(arg, "plain"))
                return COLOR_MOVED_PLAIN;
 +      else if (!strcmp(arg, "blocks"))
 +              return COLOR_MOVED_BLOCKS;
        else if (!strcmp(arg, "zebra"))
                return COLOR_MOVED_ZEBRA;
        else if (!strcmp(arg, "default"))
                return COLOR_MOVED_DEFAULT;
+       else if (!strcmp(arg, "dimmed-zebra"))
+               return COLOR_MOVED_ZEBRA_DIM;
        else if (!strcmp(arg, "dimmed_zebra"))
                return COLOR_MOVED_ZEBRA_DIM;
        else
-               return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed_zebra', 'plain'"));
 -              return error(_("color moved setting must be one of 'no', 'default', 'zebra', 'dimmed-zebra', 'plain'"));
++              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)
 +{
 +      int ret = 0;
 +      struct string_list l = STRING_LIST_INIT_DUP;
 +      struct string_list_item *i;
 +
 +      string_list_split(&l, arg, ',', -1);
 +
 +      for_each_string_list_item(i, &l) {
 +              struct strbuf sb = STRBUF_INIT;
 +              strbuf_addstr(&sb, i->string);
 +              strbuf_trim(&sb);
 +
 +              if (!strcmp(sb.buf, "ignore-space-change"))
 +                      ret |= XDF_IGNORE_WHITESPACE_CHANGE;
 +              else if (!strcmp(sb.buf, "ignore-space-at-eol"))
 +                      ret |= XDF_IGNORE_WHITESPACE_AT_EOL;
 +              else if (!strcmp(sb.buf, "ignore-all-space"))
 +                      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);
 +
 +              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"));
 +
 +      string_list_clear(&l, 0);
 +
 +      return ret;
  }
  
  int git_diff_ui_config(const char *var, const char *value, void *cb)
                diff_color_moved_default = cm;
                return 0;
        }
 +      if (!strcmp(var, "diff.colormovedws")) {
 +              int cm = parse_color_moved_ws(value);
 +              if (cm < 0)
 +                      return -1;
 +              diff_color_moved_ws_default = cm;
 +              return 0;
 +      }
        if (!strcmp(var, "diff.context")) {
                diff_context_default = git_config_int(var, value);
                if (diff_context_default < 0)
@@@ -744,116 -707,16 +746,116 @@@ struct moved_entry 
        struct hashmap_entry ent;
        const struct emitted_diff_symbol *es;
        struct moved_entry *next_line;
 +      struct ws_delta *wsd;
  };
  
 -static int moved_entry_cmp(const struct diff_options *diffopt,
 -                         const struct moved_entry *a,
 -                         const struct moved_entry *b,
 +/**
 + * The struct ws_delta holds white space differences between moved lines, i.e.
 + * between '+' and '-' lines that have been detected to be a move.
 + * The string contains the difference in leading white spaces, before the
 + * rest of the line is compared using the white space config for move
 + * coloring. The current_longer indicates if the first string in the
 + * comparision is longer than the second.
 + */
 +struct ws_delta {
 +      char *string;
 +      unsigned int current_longer : 1;
 +};
 +#define WS_DELTA_INIT { NULL, 0 }
 +
 +static int compute_ws_delta(const struct emitted_diff_symbol *a,
 +                           const struct emitted_diff_symbol *b,
 +                           struct ws_delta *out)
 +{
 +      const struct emitted_diff_symbol *longer =  a->len > b->len ? a : b;
 +      const struct emitted_diff_symbol *shorter = a->len > b->len ? b : a;
 +      int d = longer->len - shorter->len;
 +
 +      out->string = xmemdupz(longer->line, d);
 +      out->current_longer = (a == longer);
 +
 +      return !strncmp(longer->line + d, shorter->line, shorter->len);
 +}
 +
 +static int cmp_in_block_with_wsd(const struct diff_options *o,
 +                               const struct moved_entry *cur,
 +                               const struct moved_entry *match,
 +                               struct moved_entry *pmb,
 +                               int n)
 +{
 +      struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
 +      int al = cur->es->len, cl = l->len;
 +      const char *a = cur->es->line,
 +                 *b = match->es->line,
 +                 *c = l->line;
 +
 +      int wslen;
 +
 +      /*
 +       * We need to check if 'cur' is equal to 'match'.
 +       * As those are from the same (+/-) side, we do not need to adjust for
 +       * indent changes. However these were found using fuzzy matching
 +       * so we do have to check if they are equal.
 +       */
 +      if (strcmp(a, b))
 +              return 1;
 +
 +      if (!pmb->wsd)
 +              /*
 +               * No white space delta was carried forward? This can happen
 +               * when we exit early in this function and do not carry
 +               * forward ws.
 +               */
 +              return 1;
 +
 +      /*
 +       * The indent changes of the block are known and carried forward in
 +       * pmb->wsd; however we need to check if the indent changes of the
 +       * current line are still the same as before.
 +       *
 +       * To do so we need to compare 'l' to 'cur', adjusting the
 +       * one of them for the white spaces, depending which was longer.
 +       */
 +
 +      wslen = strlen(pmb->wsd->string);
 +      if (pmb->wsd->current_longer) {
 +              c += wslen;
 +              cl -= wslen;
 +      } else {
 +              a += wslen;
 +              al -= wslen;
 +      }
 +
 +      if (strcmp(a, c))
 +              return 1;
 +
 +      return 0;
 +}
 +
 +static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
 +                         const void *entry,
 +                         const void *entry_or_key,
                           const void *keydata)
  {
 +      const struct diff_options *diffopt = hashmap_cmp_fn_data;
 +      const struct moved_entry *a = entry;
 +      const struct moved_entry *b = entry_or_key;
 +      unsigned flags = diffopt->color_moved_ws_handling
 +                       & XDF_WHITESPACE_FLAGS;
 +
 +      if (diffopt->color_moved_ws_handling &
 +          COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
 +              /*
 +               * As there is not specific white space config given,
 +               * we'd need to check for a new block, so ignore all
 +               * white space. The setup of the white space
 +               * configuration for the next block is done else where
 +               */
 +              flags |= XDF_IGNORE_WHITESPACE;
 +
        return !xdiff_compare_lines(a->es->line, a->es->len,
                                    b->es->line, b->es->len,
 -                                  diffopt->xdl_opts);
 +                                  flags);
  }
  
  static struct moved_entry *prepare_entry(struct diff_options *o,
  {
        struct moved_entry *ret = xmalloc(sizeof(*ret));
        struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
 +      unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
  
 -      ret->ent.hash = xdiff_hash_string(l->line, l->len, o->xdl_opts);
 +      ret->ent.hash = xdiff_hash_string(l->line, l->len, flags);
        ret->es = l;
        ret->next_line = NULL;
 +      ret->wsd = NULL;
  
        return ret;
  }
@@@ -903,56 -764,6 +905,56 @@@ static void add_lines_to_move_detection
        }
  }
  
 +static void pmb_advance_or_null(struct diff_options *o,
 +                              struct moved_entry *match,
 +                              struct hashmap *hm,
 +                              struct moved_entry **pmb,
 +                              int pmb_nr)
 +{
 +      int i;
 +      for (i = 0; i < pmb_nr; i++) {
 +              struct moved_entry *prev = pmb[i];
 +              struct moved_entry *cur = (prev && prev->next_line) ?
 +                              prev->next_line : NULL;
 +              if (cur && !hm->cmpfn(o, cur, match, NULL)) {
 +                      pmb[i] = cur;
 +              } else {
 +                      pmb[i] = NULL;
 +              }
 +      }
 +}
 +
 +static void pmb_advance_or_null_multi_match(struct diff_options *o,
 +                                          struct moved_entry *match,
 +                                          struct hashmap *hm,
 +                                          struct moved_entry **pmb,
 +                                          int pmb_nr, int n)
 +{
 +      int i;
 +      char *got_match = xcalloc(1, pmb_nr);
 +
 +      for (; match; match = hashmap_get_next(hm, match)) {
 +              for (i = 0; i < pmb_nr; i++) {
 +                      struct moved_entry *prev = pmb[i];
 +                      struct moved_entry *cur = (prev && prev->next_line) ?
 +                                      prev->next_line : NULL;
 +                      if (!cur)
 +                              continue;
 +                      if (!cmp_in_block_with_wsd(o, cur, match, pmb[i], n))
 +                              got_match[i] |= 1;
 +              }
 +      }
 +
 +      for (i = 0; i < pmb_nr; i++) {
 +              if (got_match[i]) {
 +                      /* Carry the white space delta forward */
 +                      pmb[i]->next_line->wsd = pmb[i]->wsd;
 +                      pmb[i] = pmb[i]->next_line;
 +              } else
 +                      pmb[i] = NULL;
 +      }
 +}
 +
  static int shrink_potential_moved_blocks(struct moved_entry **pmb,
                                         int pmb_nr)
  {
  
                if (lp < pmb_nr && rp > -1 && lp < rp) {
                        pmb[lp] = pmb[rp];
 +                      if (pmb[rp]->wsd) {
 +                              free(pmb[rp]->wsd->string);
 +                              FREE_AND_NULL(pmb[rp]->wsd);
 +                      }
                        pmb[rp] = NULL;
                        rp--;
                        lp++;
@@@ -1031,18 -838,19 +1033,18 @@@ static void mark_color_as_moved(struct 
                struct moved_entry *key;
                struct moved_entry *match = NULL;
                struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
 -              int i;
  
                switch (l->s) {
                case DIFF_SYMBOL_PLUS:
                        hm = del_lines;
                        key = prepare_entry(o, n);
 -                      match = hashmap_get(hm, key, o);
 +                      match = hashmap_get(hm, key, NULL);
                        free(key);
                        break;
                case DIFF_SYMBOL_MINUS:
                        hm = add_lines;
                        key = prepare_entry(o, n);
 -                      match = hashmap_get(hm, key, o);
 +                      match = hashmap_get(hm, key, NULL);
                        free(key);
                        break;
                default:
                if (o->color_moved == COLOR_MOVED_PLAIN)
                        continue;
  
 -              /* Check any potential block runs, advance each or nullify */
 -              for (i = 0; i < pmb_nr; i++) {
 -                      struct moved_entry *p = pmb[i];
 -                      struct moved_entry *pnext = (p && p->next_line) ?
 -                                      p->next_line : NULL;
 -                      if (pnext && !hm->cmpfn(o, pnext, match, NULL)) {
 -                              pmb[i] = p->next_line;
 -                      } else {
 -                              pmb[i] = NULL;
 -                      }
 -              }
 +              if (o->color_moved_ws_handling &
 +                  COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
 +                      pmb_advance_or_null_multi_match(o, match, hm, pmb, pmb_nr, n);
 +              else
 +                      pmb_advance_or_null(o, match, hm, pmb, pmb_nr);
  
                pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
  
                         */
                        for (; match; match = hashmap_get_next(hm, match)) {
                                ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
 -                              pmb[pmb_nr++] = match;
 +                              if (o->color_moved_ws_handling &
 +                                  COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
 +                                      struct ws_delta *wsd = xmalloc(sizeof(*match->wsd));
 +                                      if (compute_ws_delta(l, match->es, wsd)) {
 +                                              match->wsd = wsd;
 +                                              pmb[pmb_nr++] = match;
 +                                      } else
 +                                              free(wsd);
 +                              } else {
 +                                      pmb[pmb_nr++] = match;
 +                              }
                        }
  
                        flipped_block = (flipped_block + 1) % 2;
  
                block_length++;
  
 -              if (flipped_block)
 +              if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
                        l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
        }
        adjust_last_block(o, n, block_length);
@@@ -1382,7 -1186,7 +1384,7 @@@ static void emit_diff_symbol_from_struc
                fputs(o->stat_sep, o->file);
                break;
        default:
 -              die("BUG: unknown diff symbol");
 +              BUG("unknown diff symbol");
        }
        strbuf_release(&sb);
  }
@@@ -1541,7 -1345,7 +1543,7 @@@ static struct diff_tempfile *claim_diff
        for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
                if (!diff_temp[i].name)
                        return diff_temp + i;
 -      die("BUG: diff is failing to clean up its tempfiles");
 +      BUG("diff is failing to clean up its tempfiles");
  }
  
  static void remove_tempfile(void)
@@@ -1702,7 -1506,7 +1704,7 @@@ struct diff_words_style_elem 
  
  struct diff_words_style {
        enum diff_words_type type;
 -      struct diff_words_style_elem new, old, ctx;
 +      struct diff_words_style_elem new_word, old_word, ctx;
        const char *newline;
  };
  
@@@ -1853,12 -1657,12 +1855,12 @@@ static void fn_out_diff_words_aux(void 
        }
        if (minus_begin != minus_end) {
                fn_out_diff_words_write_helper(diff_words->opt,
 -                              &style->old, style->newline,
 +                              &style->old_word, style->newline,
                                minus_end - minus_begin, minus_begin);
        }
        if (plus_begin != plus_end) {
                fn_out_diff_words_write_helper(diff_words->opt,
 -                              &style->new, style->newline,
 +                              &style->new_word, style->newline,
                                plus_end - plus_begin, plus_begin);
        }
  
@@@ -1956,7 -1760,7 +1958,7 @@@ static void diff_words_show(struct diff
                emit_diff_symbol(diff_words->opt, DIFF_SYMBOL_WORD_DIFF,
                                 line_prefix, strlen(line_prefix), 0);
                fn_out_diff_words_write_helper(diff_words->opt,
 -                      &style->old, style->newline,
 +                      &style->old_word, style->newline,
                        diff_words->minus.text.size,
                        diff_words->minus.text.ptr);
                diff_words->minus.text.size = 0;
@@@ -2081,8 -1885,8 +2083,8 @@@ static void init_diff_words_data(struc
        }
        if (want_color(o->use_color)) {
                struct diff_words_style *st = ecbdata->diff_words->style;
 -              st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
 -              st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
 +              st->old_word.color = diff_get_color_opt(o, DIFF_FILE_OLD);
 +              st->new_word.color = diff_get_color_opt(o, DIFF_FILE_NEW);
                st->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT);
        }
  }
@@@ -2243,10 -2047,11 +2245,10 @@@ static void fn_out_consume(void *priv, 
        }
  }
  
 -static char *pprint_rename(const char *a, const char *b)
 +static void pprint_rename(struct strbuf *name, const char *a, const char *b)
  {
 -      const char *old = a;
 -      const char *new = b;
 -      struct strbuf name = STRBUF_INIT;
 +      const char *old_name = a;
 +      const char *new_name = b;
        int pfx_length, sfx_length;
        int pfx_adjust_for_slash;
        int len_a = strlen(a);
        int qlen_b = quote_c_style(b, NULL, NULL, 0);
  
        if (qlen_a || qlen_b) {
 -              quote_c_style(a, &name, NULL, 0);
 -              strbuf_addstr(&name, " => ");
 -              quote_c_style(b, &name, NULL, 0);
 -              return strbuf_detach(&name, NULL);
 +              quote_c_style(a, name, NULL, 0);
 +              strbuf_addstr(name, " => ");
 +              quote_c_style(b, name, NULL, 0);
 +              return;
        }
  
        /* Find common prefix */
        pfx_length = 0;
 -      while (*old && *new && *old == *new) {
 -              if (*old == '/')
 -                      pfx_length = old - a + 1;
 -              old++;
 -              new++;
 +      while (*old_name && *new_name && *old_name == *new_name) {
 +              if (*old_name == '/')
 +                      pfx_length = old_name - a + 1;
 +              old_name++;
 +              new_name++;
        }
  
        /* Find common suffix */
 -      old = a + len_a;
 -      new = b + len_b;
 +      old_name = a + len_a;
 +      new_name = b + len_b;
        sfx_length = 0;
        /*
         * If there is a common prefix, it must end in a slash.  In
         * underrun the input strings.
         */
        pfx_adjust_for_slash = (pfx_length ? 1 : 0);
 -      while (a + pfx_length - pfx_adjust_for_slash <= old &&
 -             b + pfx_length - pfx_adjust_for_slash <= new &&
 -             *old == *new) {
 -              if (*old == '/')
 -                      sfx_length = len_a - (old - a);
 -              old--;
 -              new--;
 +      while (a + pfx_length - pfx_adjust_for_slash <= old_name &&
 +             b + pfx_length - pfx_adjust_for_slash <= new_name &&
 +             *old_name == *new_name) {
 +              if (*old_name == '/')
 +                      sfx_length = len_a - (old_name - a);
 +              old_name--;
 +              new_name--;
        }
  
        /*
        if (b_midlen < 0)
                b_midlen = 0;
  
 -      strbuf_grow(&name, pfx_length + a_midlen + b_midlen + sfx_length + 7);
 +      strbuf_grow(name, pfx_length + a_midlen + b_midlen + sfx_length + 7);
        if (pfx_length + sfx_length) {
 -              strbuf_add(&name, a, pfx_length);
 -              strbuf_addch(&name, '{');
 +              strbuf_add(name, a, pfx_length);
 +              strbuf_addch(name, '{');
        }
 -      strbuf_add(&name, a + pfx_length, a_midlen);
 -      strbuf_addstr(&name, " => ");
 -      strbuf_add(&name, b + pfx_length, b_midlen);
 +      strbuf_add(name, a + pfx_length, a_midlen);
 +      strbuf_addstr(name, " => ");
 +      strbuf_add(name, b + pfx_length, b_midlen);
        if (pfx_length + sfx_length) {
 -              strbuf_addch(&name, '}');
 -              strbuf_add(&name, a + len_a - sfx_length, sfx_length);
 +              strbuf_addch(name, '}');
 +              strbuf_add(name, a + len_a - sfx_length, sfx_length);
        }
 -      return strbuf_detach(&name, NULL);
  }
  
  struct diffstat_t {
                char *from_name;
                char *name;
                char *print_name;
 +              const char *comments;
                unsigned is_unmerged:1;
                unsigned is_binary:1;
                unsigned is_renamed:1;
@@@ -2394,20 -2199,23 +2396,20 @@@ static void show_graph(struct strbuf *o
  
  static void fill_print_name(struct diffstat_file *file)
  {
 -      char *pname;
 +      struct strbuf pname = STRBUF_INIT;
  
        if (file->print_name)
                return;
  
 -      if (!file->is_renamed) {
 -              struct strbuf buf = STRBUF_INIT;
 -              if (quote_c_style(file->name, &buf, NULL, 0)) {
 -                      pname = strbuf_detach(&buf, NULL);
 -              } else {
 -                      pname = file->name;
 -                      strbuf_release(&buf);
 -              }
 -      } else {
 -              pname = pprint_rename(file->from_name, file->name);
 -      }
 -      file->print_name = pname;
 +      if (file->is_renamed)
 +              pprint_rename(&pname, file->from_name, file->name);
 +      else
 +              quote_c_style(file->name, &pname, NULL, 0);
 +
 +      if (file->comments)
 +              strbuf_addf(&pname, " (%s)", file->comments);
 +
 +      file->print_name = strbuf_detach(&pname, NULL);
  }
  
  static void print_stat_summary_inserts_deletes(struct diff_options *options,
@@@ -2788,14 -2596,14 +2790,14 @@@ struct dirstat_dir 
  static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
                unsigned long changed, const char *base, int baselen)
  {
 -      unsigned long this_dir = 0;
 +      unsigned long sum_changes = 0;
        unsigned int sources = 0;
        const char *line_prefix = diff_line_prefix(opt);
  
        while (dir->nr) {
                struct dirstat_file *f = dir->files;
                int namelen = strlen(f->name);
 -              unsigned long this;
 +              unsigned long changes;
                char *slash;
  
                if (namelen < baselen)
                slash = strchr(f->name + baselen, '/');
                if (slash) {
                        int newbaselen = slash + 1 - f->name;
 -                      this = gather_dirstat(opt, dir, changed, f->name, newbaselen);
 +                      changes = gather_dirstat(opt, dir, changed, f->name, newbaselen);
                        sources++;
                } else {
 -                      this = f->changed;
 +                      changes = f->changed;
                        dir->files++;
                        dir->nr--;
                        sources += 2;
                }
 -              this_dir += this;
 +              sum_changes += changes;
        }
  
        /*
         *    under this directory (sources == 1).
         */
        if (baselen && sources != 1) {
 -              if (this_dir) {
 -                      int permille = this_dir * 1000 / changed;
 +              if (sum_changes) {
 +                      int permille = sum_changes * 1000 / changed;
                        if (permille >= dir->permille) {
                                fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
                                        permille / 10, permille % 10, baselen, base);
                        }
                }
        }
 -      return this_dir;
 +      return sum_changes;
  }
  
  static int dirstat_compare(const void *_a, const void *_b)
@@@ -2991,7 -2799,8 +2993,7 @@@ static void free_diffstat_info(struct d
        int i;
        for (i = 0; i < diffstat->nr; i++) {
                struct diffstat_file *f = diffstat->files[i];
 -              if (f->name != f->print_name)
 -                      free(f->print_name);
 +              free(f->print_name);
                free(f->name);
                free(f->from_name);
                free(f);
@@@ -3441,32 -3250,6 +3443,32 @@@ static void builtin_diff(const char *na
        return;
  }
  
 +static char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
 +{
 +      if (!is_renamed) {
 +              if (p->status == DIFF_STATUS_ADDED) {
 +                      if (S_ISLNK(p->two->mode))
 +                              return "new +l";
 +                      else if ((p->two->mode & 0777) == 0755)
 +                              return "new +x";
 +                      else
 +                              return "new";
 +              } else if (p->status == DIFF_STATUS_DELETED)
 +                      return "gone";
 +      }
 +      if (S_ISLNK(p->one->mode) && !S_ISLNK(p->two->mode))
 +              return "mode -l";
 +      else if (!S_ISLNK(p->one->mode) && S_ISLNK(p->two->mode))
 +              return "mode +l";
 +      else if ((p->one->mode & 0777) == 0644 &&
 +               (p->two->mode & 0777) == 0755)
 +              return "mode +x";
 +      else if ((p->one->mode & 0777) == 0755 &&
 +               (p->two->mode & 0777) == 0644)
 +              return "mode -x";
 +      return NULL;
 +}
 +
  static void builtin_diffstat(const char *name_a, const char *name_b,
                             struct diff_filespec *one,
                             struct diff_filespec *two,
  
        data = diffstat_add(diffstat, name_a, name_b);
        data->is_interesting = p->status != DIFF_STATUS_UNKNOWN;
 +      if (o->flags.stat_with_summary)
 +              data->comments = get_compact_summary(p, data->is_renamed);
  
        if (!one || !two) {
                data->is_unmerged = 1;
@@@ -3670,7 -3451,7 +3672,7 @@@ static int reuse_worktree_file(const ch
         * objects however would tend to be slower as they need
         * to be individually opened and inflated.
         */
 -      if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(oid->hash))
 +      if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
                return 0;
  
        /*
@@@ -3741,13 -3522,13 +3743,13 @@@ int diff_populate_filespec(struct diff_
  {
        int size_only = flags & CHECK_SIZE_ONLY;
        int err = 0;
 +      int conv_flags = global_conv_flags_eol;
        /*
         * demote FAIL to WARN to allow inspecting the situation
         * instead of refusing.
         */
 -      enum safe_crlf crlf_warn = (safe_crlf == SAFE_CRLF_FAIL
 -                                  ? SAFE_CRLF_WARN
 -                                  : safe_crlf);
 +      if (conv_flags & CONV_EOL_RNDTRP_DIE)
 +              conv_flags = CONV_EOL_RNDTRP_WARN;
  
        if (!DIFF_FILE_VALID(s))
                die("internal error: asking to populate invalid file.");
                /*
                 * Convert from working tree format to canonical git format
                 */
 -              if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {
 +              if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, conv_flags)) {
                        size_t size = 0;
                        munmap(s->data, s->size);
                        s->should_munmap = 0;
        else {
                enum object_type type;
                if (size_only || (flags & CHECK_BINARY)) {
 -                      type = sha1_object_info(s->oid.hash, &s->size);
 +                      type = oid_object_info(the_repository, &s->oid,
 +                                             &s->size);
                        if (type < 0)
                                die("unable to read %s",
                                    oid_to_hex(&s->oid));
                                return 0;
                        }
                }
 -              s->data = read_sha1_file(s->oid.hash, &type, &s->size);
 +              s->data = read_object_file(&s->oid, &type, &s->size);
                if (!s->data)
                        die("unable to read %s", oid_to_hex(&s->oid));
                s->should_free = 1;
@@@ -3882,15 -3662,15 +3884,15 @@@ static void prep_temp_blob(const char *
                           int mode)
  {
        struct strbuf buf = STRBUF_INIT;
 -      struct strbuf template = STRBUF_INIT;
 +      struct strbuf tempfile = STRBUF_INIT;
        char *path_dup = xstrdup(path);
        const char *base = basename(path_dup);
  
        /* Generate "XXXXXX_basename.ext" */
 -      strbuf_addstr(&template, "XXXXXX_");
 -      strbuf_addstr(&template, base);
 +      strbuf_addstr(&tempfile, "XXXXXX_");
 +      strbuf_addstr(&tempfile, base);
  
 -      temp->tempfile = mks_tempfile_ts(template.buf, strlen(base) + 1);
 +      temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
        if (!temp->tempfile)
                die_errno("unable to create temp-file");
        if (convert_to_working_tree(path,
        oid_to_hex_r(temp->hex, oid);
        xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);
        strbuf_release(&buf);
 -      strbuf_release(&template);
 +      strbuf_release(&tempfile);
        free(path_dup);
  }
  
@@@ -4033,13 -3813,13 +4035,13 @@@ static int similarity_index(struct diff
  static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
  {
        if (startup_info->have_repository)
 -              return find_unique_abbrev(oid->hash, abbrev);
 +              return find_unique_abbrev(oid, abbrev);
        else {
                char *hex = oid_to_hex(oid);
                if (abbrev < 0)
                        abbrev = FALLBACK_DEFAULT_ABBREV;
 -              if (abbrev > GIT_SHA1_HEXSZ)
 -                      die("BUG: oid abbreviation out of range: %d", abbrev);
 +              if (abbrev > the_hash_algo->hexsz)
 +                      BUG("oid abbreviation out of range: %d", abbrev);
                if (abbrev)
                        hex[abbrev] = '\0';
                return hex;
@@@ -4096,14 -3876,13 +4098,14 @@@ static void fill_metainfo(struct strbu
                *must_show_header = 0;
        }
        if (one && two && oidcmp(&one->oid, &two->oid)) {
 -              int abbrev = o->flags.full_index ? 40 : DEFAULT_ABBREV;
 +              const unsigned hexsz = the_hash_algo->hexsz;
 +              int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV;
  
                if (o->flags.binary) {
                        mmfile_t mf;
                        if ((!fill_mmfile(&mf, one) && diff_filespec_is_binary(one)) ||
                            (!fill_mmfile(&mf, two) && diff_filespec_is_binary(two)))
 -                              abbrev = 40;
 +                              abbrev = hexsz;
                }
                strbuf_addf(msg, "%s%sindex %s..%s", line_prefix, set,
                            diff_abbrev_oid(&one->oid, abbrev),
@@@ -4309,7 -4088,6 +4311,7 @@@ void diff_setup(struct diff_options *op
        options->interhunkcontext = diff_interhunk_context_default;
        options->ws_error_highlight = ws_error_highlight_default;
        options->flags.rename_empty = 1;
 +      options->objfind = NULL;
  
        /* pathchange left =NULL by default */
        options->change = diff_change;
        }
  
        options->color_moved = diff_color_moved_default;
 +      options->color_moved_ws_handling = diff_color_moved_ws_default;
  }
  
  void diff_setup_done(struct diff_options *options)
  {
 -      int count = 0;
 +      unsigned check_mask = DIFF_FORMAT_NAME |
 +                            DIFF_FORMAT_NAME_STATUS |
 +                            DIFF_FORMAT_CHECKDIFF |
 +                            DIFF_FORMAT_NO_OUTPUT;
 +      /*
 +       * This must be signed because we're comparing against a potentially
 +       * negative value.
 +       */
 +      const int hexsz = the_hash_algo->hexsz;
  
        if (options->set_default)
                options->set_default(options);
  
 -      if (options->output_format & DIFF_FORMAT_NAME)
 -              count++;
 -      if (options->output_format & DIFF_FORMAT_NAME_STATUS)
 -              count++;
 -      if (options->output_format & DIFF_FORMAT_CHECKDIFF)
 -              count++;
 -      if (options->output_format & DIFF_FORMAT_NO_OUTPUT)
 -              count++;
 -      if (count > 1)
 +      if (HAS_MULTI_BITS(options->output_format & check_mask))
                die(_("--name-only, --name-status, --check and -s are mutually exclusive"));
  
 +      if (HAS_MULTI_BITS(options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK))
 +              die(_("-G, -S and --find-object are mutually exclusive"));
 +
        /*
         * Most of the time we can say "there are changes"
         * only by checking if there are changed paths, but
        /*
         * Also pickaxe would not work very well if you do not say recursive
         */
 -      if (options->pickaxe)
 +      if (options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK)
                options->flags.recursive = 1;
        /*
         * When patches are generated, submodules diffed against the work tree
                         */
                        read_cache();
        }
 -      if (40 < options->abbrev)
 -              options->abbrev = 40; /* full */
 +      if (hexsz < options->abbrev)
 +              options->abbrev = hexsz; /* full */
  
        /*
         * It does not make sense to show the first hit we happened
@@@ -4540,7 -4314,7 +4542,7 @@@ static int stat_opt(struct diff_option
        int argcount = 1;
  
        if (!skip_prefix(arg, "--stat", &arg))
 -              die("BUG: stat option does not begin with --stat: %s", arg);
 +              BUG("stat option does not begin with --stat: %s", arg);
        end = (char *)arg;
  
        switch (*arg) {
@@@ -4717,23 -4491,6 +4719,23 @@@ static int parse_ws_error_highlight_opt
        return 1;
  }
  
 +static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 +{
 +      struct object_id oid;
 +
 +      if (get_oid(arg, &oid))
 +              return error("unable to resolve '%s'", arg);
 +
 +      if (!opt->objfind)
 +              opt->objfind = xcalloc(1, sizeof(*opt->objfind));
 +
 +      opt->pickaxe_opts |= DIFF_PICKAXE_KIND_OBJFIND;
 +      opt->flags.recursive = 1;
 +      opt->flags.tree_in_recursive = 1;
 +      oidset_insert(opt->objfind, &oid);
 +      return 1;
 +}
 +
  int diff_opt_parse(struct diff_options *options,
                   const char **av, int ac, const char *prefix)
  {
        else if (starts_with(arg, "--stat"))
                /* --stat, --stat-width, --stat-name-width, or --stat-count */
                return stat_opt(options, av);
 +      else if (!strcmp(arg, "--compact-summary")) {
 +               options->flags.stat_with_summary = 1;
 +               options->output_format |= DIFF_FORMAT_DIFFSTAT;
 +      } else if (!strcmp(arg, "--no-compact-summary"))
 +               options->flags.stat_with_summary = 0;
  
        /* renames options */
        else if (starts_with(arg, "-B") ||
                if (cm < 0)
                        die("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);
        } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
        else if ((argcount = short_opt('O', av, &optarg))) {
                options->orderfile = prefix_filename(prefix, optarg);
                return argcount;
 -      }
 +      } else if (skip_prefix(arg, "--find-object=", &arg))
 +              return parse_objfind_opt(options, arg);
        else if ((argcount = parse_long_opt("diff-filter", av, &optarg))) {
                int offending = parse_diff_filter_opt(optarg, options);
                if (offending)
                options->abbrev = strtoul(arg, NULL, 10);
                if (options->abbrev < MINIMUM_ABBREV)
                        options->abbrev = MINIMUM_ABBREV;
 -              else if (40 < options->abbrev)
 -                      options->abbrev = 40;
 +              else if (the_hash_algo->hexsz < options->abbrev)
 +                      options->abbrev = the_hash_algo->hexsz;
        }
        else if ((argcount = parse_long_opt("src-prefix", av, &optarg))) {
                options->a_prefix = optarg;
@@@ -5156,7 -4905,7 +5158,7 @@@ const char *diff_aligned_abbrev(const s
        const char *abbrev;
  
        /* Do we want all 40 hex characters? */
 -      if (len == GIT_SHA1_HEXSZ)
 +      if (len == the_hash_algo->hexsz)
                return oid_to_hex(oid);
  
        /* An abbreviated value is fine, possibly followed by an ellipsis. */
         * the automatic sizing is supposed to give abblen that ensures
         * uniqueness across all objects (statistically speaking).
         */
 -      if (abblen < GIT_SHA1_HEXSZ - 3) {
 +      if (abblen < the_hash_algo->hexsz - 3) {
                static char hex[GIT_MAX_HEXSZ + 1];
                if (len < abblen && abblen <= len + 2)
                        xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
@@@ -5477,12 -5226,10 +5479,12 @@@ static void show_rename_copy(struct dif
                struct diff_filepair *p)
  {
        struct strbuf sb = STRBUF_INIT;
 -      char *names = pprint_rename(p->one->path, p->two->path);
 +      struct strbuf names = STRBUF_INIT;
 +
 +      pprint_rename(&names, p->one->path, p->two->path);
        strbuf_addf(&sb, " %s %s (%d%%)\n",
 -                      renamecopy, names, similarity_index(p));
 -      free(names);
 +                  renamecopy, names.buf, similarity_index(p));
 +      strbuf_release(&names);
        emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
                                 sb.buf, sb.len, 0);
        show_mode_change(opt, p, 0);
@@@ -5727,7 -5474,7 +5729,7 @@@ static void diff_flush_patch_all_file_p
        struct diff_queue_struct *q = &diff_queued_diff;
  
        if (WSEH_NEW & WS_RULE_MASK)
 -              die("BUG: WS rules bit mask overlaps with diff symbol flags");
 +              BUG("WS rules bit mask overlaps with diff symbol flags");
  
        if (o->color_moved)
                o->emitted_symbols = &esm;
                if (o->color_moved) {
                        struct hashmap add_lines, del_lines;
  
 -                      hashmap_init(&del_lines,
 -                                   (hashmap_cmp_fn)moved_entry_cmp, o, 0);
 -                      hashmap_init(&add_lines,
 -                                   (hashmap_cmp_fn)moved_entry_cmp, o, 0);
 +                      if (o->color_moved_ws_handling &
 +                          COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
 +                              o->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE;
 +
 +                      hashmap_init(&del_lines, moved_entry_cmp, o, 0);
 +                      hashmap_init(&add_lines, moved_entry_cmp, o, 0);
  
                        add_lines_to_move_detection(o, &add_lines, &del_lines);
                        mark_color_as_moved(o, &add_lines, &del_lines);
@@@ -6041,7 -5786,7 +6043,7 @@@ void diffcore_std(struct diff_options *
                if (options->break_opt != -1)
                        diffcore_merge_broken();
        }
 -      if (options->pickaxe)
 +      if (options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK)
                diffcore_pickaxe(options);
        if (options->orderfile)
                diffcore_order(options->orderfile);
@@@ -6263,7 -6008,7 +6265,7 @@@ size_t fill_textconv(struct userdiff_dr
        }
  
        if (!driver->textconv)
 -              die("BUG: fill_textconv called with non-textconv driver");
 +              BUG("fill_textconv called with non-textconv driver");
  
        if (driver->textconv_cache && df->oid_valid) {
                *outbuf = notes_cache_get(driver->textconv_cache,
index 41facf7abf9bff5cc39419b41998836018257f79,8cdfa225ef6cecb8d44b56c90da5b7e6f0355175..e2dc1895ba3942954dfaba3c0af914494d2aa317
@@@ -1223,7 -1223,7 +1223,7 @@@ test_expect_success 'plain moved code, 
        test_cmp expected actual
  '
  
 -test_expect_success 'detect permutations inside moved code -- dimmed-zebra' '
 +test_expect_success 'detect blocks of moved code' '
        git reset --hard &&
        cat <<-\EOF >lines.txt &&
                long line 1
        test_config color.diff.newMovedDimmed "normal cyan" &&
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
 -      git diff HEAD --no-renames --color-moved=dimmed-zebra --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved=blocks --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
 +      cat <<-\EOF >expected &&
 +      <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
 +      <BOLD>--- a/lines.txt<RESET>
 +      <BOLD>+++ b/lines.txt<RESET>
 +      <CYAN>@@ -1,16 +1,16 @@<RESET>
 +      <MAGENTA>-long line 1<RESET>
 +      <MAGENTA>-long line 2<RESET>
 +      <MAGENTA>-long line 3<RESET>
 +       line 4<RESET>
 +       line 5<RESET>
 +       line 6<RESET>
 +       line 7<RESET>
 +       line 8<RESET>
 +       line 9<RESET>
 +      <CYAN>+<RESET><CYAN>long line 1<RESET>
 +      <CYAN>+<RESET><CYAN>long line 2<RESET>
 +      <CYAN>+<RESET><CYAN>long line 3<RESET>
 +      <CYAN>+<RESET><CYAN>long line 14<RESET>
 +      <CYAN>+<RESET><CYAN>long line 15<RESET>
 +      <CYAN>+<RESET><CYAN>long line 16<RESET>
 +       line 10<RESET>
 +       line 11<RESET>
 +       line 12<RESET>
 +       line 13<RESET>
 +      <MAGENTA>-long line 14<RESET>
 +      <MAGENTA>-long line 15<RESET>
 +      <MAGENTA>-long line 16<RESET>
 +      EOF
 +      test_cmp expected actual
 +
 +'
 +
- test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
++test_expect_success 'detect permutations inside moved code -- dimmed-zebra' '
 +      # reuse setup from test before!
 +      test_config color.diff.oldMoved "magenta" &&
 +      test_config color.diff.newMoved "cyan" &&
 +      test_config color.diff.oldMovedAlternative "blue" &&
 +      test_config color.diff.newMovedAlternative "yellow" &&
 +      test_config color.diff.oldMovedDimmed "normal magenta" &&
 +      test_config color.diff.newMovedDimmed "normal cyan" &&
 +      test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
 +      test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
-       git diff HEAD --no-renames --color-moved=dimmed_zebra --color >actual.raw &&
++      git diff HEAD --no-renames --color-moved=dimmed-zebra --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@@ -1358,8 -1315,9 +1358,8 @@@ test_expect_success 'cmd option assume
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
        test_config diff.colorMoved zebra &&
 -      git diff HEAD --no-renames --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@@ -1437,8 -1395,9 +1437,8 @@@ test_expect_success 'move detection ign
        line 4
        line 5
        EOF
 -      git diff HEAD --no-renames --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
        EOF
        test_cmp expected actual &&
  
 -      git diff HEAD --no-renames -w --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color \
 +              --color-moved-ws=ignore-all-space >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@@ -1500,8 -1459,9 +1500,8 @@@ test_expect_success 'move detection ign
        line 5
        EOF
  
 -      git diff HEAD --no-renames --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
        EOF
        test_cmp expected actual &&
  
 -      git diff HEAD --no-renames -b --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color \
 +              --color-moved-ws=ignore-space-change >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@@ -1566,8 -1526,9 +1566,8 @@@ test_expect_success 'move detection ign
        # avoid cluttering the output with complaints about our eol whitespace
        test_config core.whitespace -blank-at-eol &&
  
 -      git diff HEAD --no-renames --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
        EOF
        test_cmp expected actual &&
  
 -      git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --no-renames --color-moved --color \
 +              --color-moved-ws=ignore-space-at-eol >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
        <BOLD>--- a/lines.txt<RESET>
@@@ -1636,8 -1597,9 +1636,8 @@@ test_expect_success '--color-moved bloc
        irrelevant_line
        EOF
  
 -      git diff HEAD --color-moved=zebra --color --no-renames |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@@ -1674,8 -1636,9 +1674,8 @@@ test_expect_success '--color-moved resp
        nineteen chars 456789
        EOF
  
 -      git diff HEAD --color-moved=zebra --color --no-renames |
 -              grep -v "index" |
 -              test_decode_color >actual &&
 +      git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@@ -1716,8 -1679,7 +1716,8 @@@ test_expect_success '--color-moved trea
        7charsA
        EOF
  
 -      git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
 +      git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@@ -1760,146 -1722,7 +1760,146 @@@ test_expect_success 'move detection wit
  
        # nor did we mess with it another way
        git diff --submodule=diff --color | test_decode_color >expect &&
 -      test_cmp expect decoded_actual
 +      test_cmp expect decoded_actual &&
 +      rm -rf bananas &&
 +      git submodule deinit bananas
 +'
 +
 +test_expect_success 'only move detection ignores white spaces' '
 +      git reset --hard &&
 +      q_to_tab <<-\EOF >text.txt &&
 +              a long line to exceed per-line minimum
 +              another long line to exceed per-line minimum
 +              original file
 +      EOF
 +      git add text.txt &&
 +      git commit -m "add text" &&
 +      q_to_tab <<-\EOF >text.txt &&
 +              Qa long line to exceed per-line minimum
 +              Qanother long line to exceed per-line minimum
 +              new file
 +      EOF
 +
 +      # Make sure we get a different diff using -w
 +      git diff --color --color-moved -w >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
 +      q_to_tab <<-\EOF >expected &&
 +      <BOLD>diff --git a/text.txt b/text.txt<RESET>
 +      <BOLD>--- a/text.txt<RESET>
 +      <BOLD>+++ b/text.txt<RESET>
 +      <CYAN>@@ -1,3 +1,3 @@<RESET>
 +       Qa long line to exceed per-line minimum<RESET>
 +       Qanother long line to exceed per-line minimum<RESET>
 +      <RED>-original file<RESET>
 +      <GREEN>+<RESET><GREEN>new file<RESET>
 +      EOF
 +      test_cmp expected actual &&
 +
 +      # And now ignoring white space only in the move detection
 +      git diff --color --color-moved \
 +              --color-moved-ws=ignore-all-space,ignore-space-change,ignore-space-at-eol >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
 +      q_to_tab <<-\EOF >expected &&
 +      <BOLD>diff --git a/text.txt b/text.txt<RESET>
 +      <BOLD>--- a/text.txt<RESET>
 +      <BOLD>+++ b/text.txt<RESET>
 +      <CYAN>@@ -1,3 +1,3 @@<RESET>
 +      <BOLD;MAGENTA>-a long line to exceed per-line minimum<RESET>
 +      <BOLD;MAGENTA>-another long line to exceed per-line minimum<RESET>
 +      <RED>-original file<RESET>
 +      <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>a long line to exceed per-line minimum<RESET>
 +      <BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>another long line to exceed per-line minimum<RESET>
 +      <GREEN>+<RESET><GREEN>new file<RESET>
 +      EOF
 +      test_cmp expected actual
 +'
 +
 +test_expect_success 'compare whitespace delta across moved blocks' '
 +
 +      git reset --hard &&
 +      q_to_tab <<-\EOF >text.txt &&
 +      QIndented
 +      QText across
 +      Qsome lines
 +      QBut! <- this stands out
 +      QAdjusting with
 +      QQdifferent starting
 +      Qwhite spaces
 +      QAnother outlier
 +      QQQIndented
 +      QQQText across
 +      QQQfive lines
 +      QQQthat has similar lines
 +      QQQto previous blocks, but with different indent
 +      QQQYetQAnotherQoutlierQ
 +      EOF
 +
 +      git add text.txt &&
 +      git commit -m "add text.txt" &&
 +
 +      q_to_tab <<-\EOF >text.txt &&
 +      QQIndented
 +      QQText across
 +      QQsome lines
 +      QQQBut! <- this stands out
 +      Adjusting with
 +      Qdifferent starting
 +      white spaces
 +      AnotherQoutlier
 +      QQIndented
 +      QQText across
 +      QQfive lines
 +      QQthat has similar lines
 +      QQto previous blocks, but with different indent
 +      QQYetQAnotherQoutlier
 +      EOF
 +
 +      git diff --color --color-moved --color-moved-ws=allow-indentation-change >actual.raw &&
 +      grep -v "index" actual.raw | test_decode_color >actual &&
 +
 +      q_to_tab <<-\EOF >expected &&
 +              <BOLD>diff --git a/text.txt b/text.txt<RESET>
 +              <BOLD>--- a/text.txt<RESET>
 +              <BOLD>+++ b/text.txt<RESET>
 +              <CYAN>@@ -1,14 +1,14 @@<RESET>
 +              <BOLD;MAGENTA>-QIndented<RESET>
 +              <BOLD;MAGENTA>-QText across<RESET>
 +              <BOLD;MAGENTA>-Qsome lines<RESET>
 +              <RED>-QBut! <- this stands out<RESET>
 +              <BOLD;MAGENTA>-QAdjusting with<RESET>
 +              <BOLD;MAGENTA>-QQdifferent starting<RESET>
 +              <BOLD;MAGENTA>-Qwhite spaces<RESET>
 +              <RED>-QAnother outlier<RESET>
 +              <BOLD;MAGENTA>-QQQIndented<RESET>
 +              <BOLD;MAGENTA>-QQQText across<RESET>
 +              <BOLD;MAGENTA>-QQQfive lines<RESET>
 +              <BOLD;MAGENTA>-QQQthat has similar lines<RESET>
 +              <BOLD;MAGENTA>-QQQto previous blocks, but with different indent<RESET>
 +              <RED>-QQQYetQAnotherQoutlierQ<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>some lines<RESET>
 +              <GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
 +              <BOLD;CYAN>+<RESET><BOLD;CYAN>Adjusting with<RESET>
 +              <BOLD;CYAN>+<RESET>Q<BOLD;CYAN>different starting<RESET>
 +              <BOLD;CYAN>+<RESET><BOLD;CYAN>white spaces<RESET>
 +              <GREEN>+<RESET><GREEN>AnotherQoutlier<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Indented<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>Text across<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>five lines<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>that has similar lines<RESET>
 +              <BOLD;CYAN>+<RESET>QQ<BOLD;CYAN>to previous blocks, but with different indent<RESET>
 +              <GREEN>+<RESET>QQ<GREEN>YetQAnotherQoutlier<RESET>
 +      EOF
 +
 +      test_cmp expected actual
 +'
 +
 +test_expect_success 'compare whitespace delta incompatible with other space options' '
 +      test_must_fail git diff \
 +              --color-moved-ws=allow-indentation-change,ignore-all-space \
 +              2>err &&
 +      test_i18ngrep allow-indentation-change err
  '
  
  test_done