Merge branch 'jc/maint-hide-cr-in-diff-from-less' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 10 Sep 2008 09:14:18 +0000 (02:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Sep 2008 09:14:18 +0000 (02:14 -0700)
* jc/maint-hide-cr-in-diff-from-less:
diff: Help "less" hide ^M from the output

1  2 
diff.c
diff --combined diff.c
index b3a7da70a59788f8edf5983e8e0b4629ea56db20,6d56c69810ed5b21beb1c0f8b50023461760d5bd..5e01b2bb27994091a0a6ec564b6e3f6a6a0f4ab5
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -511,13 -511,20 +511,20 @@@ const char *diff_get_color(int diff_use
  
  static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
  {
-       int has_trailing_newline = (len > 0 && line[len-1] == '\n');
+       int has_trailing_newline, has_trailing_carriage_return;
+       has_trailing_newline = (len > 0 && line[len-1] == '\n');
        if (has_trailing_newline)
                len--;
+       has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
+       if (has_trailing_carriage_return)
+               len--;
  
        fputs(set, file);
        fwrite(line, len, 1, file);
        fputs(reset, file);
+       if (has_trailing_carriage_return)
+               fputc('\r', file);
        if (has_trailing_newline)
                fputc('\n', file);
  }
@@@ -1072,7 -1079,7 +1079,7 @@@ static void show_dirstat(struct diff_op
        dir.alloc = 0;
        dir.nr = 0;
        dir.percent = options->dirstat_percent;
 -      dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
 +      dir.cumulative = DIFF_OPT_TST(options, DIRSTAT_CUMULATIVE);
  
        changed = 0;
        for (i = 0; i < q->nr; i++) {
@@@ -2298,7 -2305,6 +2305,7 @@@ void diff_setup(struct diff_options *op
        options->break_opt = -1;
        options->rename_limit = -1;
        options->dirstat_percent = 3;
 +      DIFF_OPT_CLR(options, DIRSTAT_CUMULATIVE);
        options->context = 3;
  
        options->change = diff_change;
@@@ -2471,10 -2477,8 +2478,10 @@@ int diff_opt_parse(struct diff_options 
                options->output_format |= DIFF_FORMAT_SHORTSTAT;
        else if (opt_arg(arg, 'X', "dirstat", &options->dirstat_percent))
                options->output_format |= DIFF_FORMAT_DIRSTAT;
 -      else if (!strcmp(arg, "--cumulative"))
 -              options->output_format |= DIFF_FORMAT_CUMULATIVE;
 +      else if (!strcmp(arg, "--cumulative")) {
 +              options->output_format |= DIFF_FORMAT_DIRSTAT;
 +              DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
 +      }
        else if (!strcmp(arg, "--check"))
                options->output_format |= DIFF_FORMAT_CHECKDIFF;
        else if (!strcmp(arg, "--summary"))