From: Junio C Hamano Date: Wed, 10 Sep 2008 09:14:18 +0000 (-0700) Subject: Merge branch 'jc/maint-hide-cr-in-diff-from-less' into maint X-Git-Tag: v1.6.0.2~11 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/26c10c7ad39357bd94129c3949fed67c39302b0f?ds=inline;hp=-c Merge branch 'jc/maint-hide-cr-in-diff-from-less' into maint * jc/maint-hide-cr-in-diff-from-less: diff: Help "less" hide ^M from the output --- 26c10c7ad39357bd94129c3949fed67c39302b0f diff --combined diff.c index b3a7da70a5,6d56c69810..5e01b2bb27 --- a/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"))