diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-09-07 23:45:40 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-09-07 23:45:40 -0700 |
commit | fdfb4cfadcfdfe4ebafd0545b5ebb661433ea66c (patch) | |
tree | 6aa57e5f061a32801c706496357f020556cff200 /combine-diff.c | |
parent | 11bd3ddb913afd9665e7e822ea54be4fc8d2d5ea (diff) | |
parent | 392809702016cde59d50a7b07e8c27f6d0ec3c3f (diff) | |
download | git-fdfb4cfadcfdfe4ebafd0545b5ebb661433ea66c.tar.gz |
Merge branch 'jc/hide-cr-in-diff-from-less'
* jc/hide-cr-in-diff-from-less:
diff: Help "less" hide ^M from the output
Diffstat (limited to 'combine-diff.c')
-rw-r--r-- | combine-diff.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/combine-diff.c b/combine-diff.c index 0cf2a830b5..dcb90b1701 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -496,6 +496,18 @@ static int hunk_comment_line(const char *bol) return (isalpha(ch) || ch == '_' || ch == '$'); } +static void show_line_to_eol(const char *line, int len, const char *reset) +{ + int saw_cr_at_eol = 0; + if (len < 0) + len = strlen(line); + saw_cr_at_eol = (len && line[len-1] == '\r'); + + printf("%.*s%s%s\n", len - saw_cr_at_eol, line, + reset, + saw_cr_at_eol ? "\r" : ""); +} + static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent, int use_color) { @@ -589,7 +601,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent, else putchar(' '); } - printf("%s%s\n", ll->line, c_reset); + show_line_to_eol(ll->line, -1, c_reset); ll = ll->next; } if (cnt < lno) @@ -613,7 +625,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent, putchar(' '); p_mask <<= 1; } - printf("%.*s%s\n", sl->len, sl->bol, c_reset); + show_line_to_eol(sl->bol, sl->len, c_reset); } } } |