Skip to content

Commit

Permalink
Handle filename with space in diff view
Browse files Browse the repository at this point in the history
As reported by Johannes Altmanninger, if the filename contains a space,
Git adds a tab at the end of the line, to satisfy GNU patch. Drop it to
correct the filename.

Fixes #1035
  • Loading branch information
koutcher committed Dec 13, 2020
1 parent 78d4fdd commit 04cde58
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,14 @@ add_line_text_at_(struct view *view, unsigned long pos, const char *text, size_t
struct line *
add_line_text_at(struct view *view, unsigned long pos, const char *text, enum line_type type, size_t cells)
{
return add_line_text_at_(view, pos, text, strlen(text), type, cells, false);
size_t textlen = strlen(text);

/* If the filename contains a space, Git adds a tab at the end of
* the line, to satisfy GNU patch. Drop it to correct the filename. */
if ((type == LINE_DIFF_ADD_FILE || type == LINE_DIFF_DEL_FILE) && text[textlen - 1] == '\t')
textlen--;

return add_line_text_at_(view, pos, text, textlen, type, cells, false);
}

struct line *
Expand Down

0 comments on commit 04cde58

Please sign in to comment.