Merge branch 'jc/hide-cr-in-diff-from-less'
* jc/hide-cr-in-diff-from-less: diff: Help "less" hide ^M from the output
This commit is contained in:
commit
fdfb4cfadc
@ -496,6 +496,18 @@ static int hunk_comment_line(const char *bol)
|
|||||||
return (isalpha(ch) || ch == '_' || ch == '$');
|
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,
|
static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
||||||
int use_color)
|
int use_color)
|
||||||
{
|
{
|
||||||
@ -589,7 +601,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
|||||||
else
|
else
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
printf("%s%s\n", ll->line, c_reset);
|
show_line_to_eol(ll->line, -1, c_reset);
|
||||||
ll = ll->next;
|
ll = ll->next;
|
||||||
}
|
}
|
||||||
if (cnt < lno)
|
if (cnt < lno)
|
||||||
@ -613,7 +625,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
|||||||
putchar(' ');
|
putchar(' ');
|
||||||
p_mask <<= 1;
|
p_mask <<= 1;
|
||||||
}
|
}
|
||||||
printf("%.*s%s\n", sl->len, sl->bol, c_reset);
|
show_line_to_eol(sl->bol, sl->len, c_reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
diff.c
9
diff.c
@ -513,13 +513,20 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
|
|||||||
|
|
||||||
static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
|
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)
|
if (has_trailing_newline)
|
||||||
len--;
|
len--;
|
||||||
|
has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
|
||||||
|
if (has_trailing_carriage_return)
|
||||||
|
len--;
|
||||||
|
|
||||||
fputs(set, file);
|
fputs(set, file);
|
||||||
fwrite(line, len, 1, file);
|
fwrite(line, len, 1, file);
|
||||||
fputs(reset, file);
|
fputs(reset, file);
|
||||||
|
if (has_trailing_carriage_return)
|
||||||
|
fputc('\r', file);
|
||||||
if (has_trailing_newline)
|
if (has_trailing_newline)
|
||||||
fputc('\n', file);
|
fputc('\n', file);
|
||||||
}
|
}
|
||||||
|
@ -178,4 +178,16 @@ test_expect_success 'trailing empty lines (2)' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'do not color trailing cr in context' '
|
||||||
|
git config --unset core.whitespace
|
||||||
|
rm -f .gitattributes &&
|
||||||
|
echo AAAQ | tr Q "\015" >G &&
|
||||||
|
git add G &&
|
||||||
|
echo BBBQ | tr Q "\015" >>G
|
||||||
|
git diff --color G | tr "\015" Q >output &&
|
||||||
|
grep "BBB.*${blue_grep}Q" output &&
|
||||||
|
grep "AAA.*\[mQ" output
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user