Merge branch 'nd/diff-flush-before-warning' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:09 +0000 (14:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:09 +0000 (14:24 -0700)
Avoid showing a warning message in the middle of a line of "git
diff" output.

* nd/diff-flush-before-warning:
diff.c: flush stdout before printing rename warnings

1  2 
diff.c
diff --cc diff.c
index db4696fdf510d47dd6d235a1c04b8cc550c8e8fe,bfd1bd2410f9d0b920fda58cb0caae33a94111e7..e9d0e38123a59f2ca54674115df4140836b98f18
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -5454,59 -4623,15 +5454,60 @@@ N_("you may want to set your %s variabl
  
  void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc)
  {
+       fflush(stdout);
        if (degraded_cc)
 -              warning(degrade_cc_to_c_warning);
 +              warning(_(degrade_cc_to_c_warning));
        else if (needed)
 -              warning(rename_limit_warning);
 +              warning(_(rename_limit_warning));
        else
                return;
 -      if (0 < needed && needed < 32767)
 -              warning(rename_limit_advice, varname, needed);
 +      if (0 < needed)
 +              warning(_(rename_limit_advice), varname, needed);
 +}
 +
 +static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 +{
 +      int i;
 +      static struct emitted_diff_symbols esm = EMITTED_DIFF_SYMBOLS_INIT;
 +      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");
 +
 +      if (o->color_moved)
 +              o->emitted_symbols = &esm;
 +
 +      for (i = 0; i < q->nr; i++) {
 +              struct diff_filepair *p = q->queue[i];
 +              if (check_pair_status(p))
 +                      diff_flush_patch(p, o);
 +      }
 +
 +      if (o->emitted_symbols) {
 +              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);
 +
 +                      add_lines_to_move_detection(o, &add_lines, &del_lines);
 +                      mark_color_as_moved(o, &add_lines, &del_lines);
 +                      if (o->color_moved == COLOR_MOVED_ZEBRA_DIM)
 +                              dim_moved_lines(o);
 +
 +                      hashmap_free(&add_lines, 0);
 +                      hashmap_free(&del_lines, 0);
 +              }
 +
 +              for (i = 0; i < esm.nr; i++)
 +                      emit_diff_symbol_from_struct(o, &esm.buf[i]);
 +
 +              for (i = 0; i < esm.nr; i++)
 +                      free((void *)esm.buf[i].line);
 +      }
 +      esm.nr = 0;
  }
  
  void diff_flush(struct diff_options *options)