From d55aeb7687448189327ad058096b55431da5ea42 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 27 Oct 2014 14:13:15 -0700 Subject: strbuf_add_commented_lines(): avoid SP-HT sequence in commented lines The strbuf_add_commented_lines() function passes a pair of prefixes, one to be used for a non-empty line, and the other for an empty line, to underlying add_lines(). The former is set to a comment char followed by a SP, while the latter is set to just the comment char. This is designed to give a SP after the comment character, e.g. "# \n", on a line with some text, and to avoid emitting an unsightly "# \n" for an empty line. Teach this machinery to also use the latter space-less prefix when the payload line begins with a tab, to show e.g. "#\t\n"; otherwise we will end up showing "# \t\n" which is similarly unsightly. Signed-off-by: Junio C Hamano --- strbuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index 33018d847f..a4486a9e49 100644 --- a/strbuf.c +++ b/strbuf.c @@ -222,7 +222,8 @@ static void add_lines(struct strbuf *out, const char *next = memchr(buf, '\n', size); next = next ? (next + 1) : (buf + size); - prefix = (prefix2 && buf[0] == '\n') ? prefix2 : prefix1; + prefix = ((prefix2 && (buf[0] == '\n' || buf[0] == '\t')) + ? prefix2 : prefix1); strbuf_addstr(out, prefix); strbuf_add(out, buf, next - buf); size -= next - buf; -- cgit v1.2.1