Merge branch 'jc/strbuf-add-lines-avoid-sp-ht-sequence'
authorJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2015 20:49:19 +0000 (12:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2015 20:49:19 +0000 (12:49 -0800)
The commented output used to blindly add a SP before the payload
line, resulting in "# \t<indented text>\n" when the payload began
with a HT. Instead, produce "#\t<indented text>\n".

* jc/strbuf-add-lines-avoid-sp-ht-sequence:
strbuf_add_commented_lines(): avoid SP-HT sequence in commented lines

strbuf.c
t/t0030-stripspace.sh
index 0346e74a47d14ef13757cadfe2a0de778b5c4cc4..88cafd4a70b8179a4e911c18704fb4ab0f2a21f5 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -229,7 +229,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;
index 0333dd9875af9fbbad04cf05eb9f0e9fe37ae182..29e91d861cbd6473d80c7343a0e292b010d83173 100755 (executable)
@@ -432,4 +432,10 @@ test_expect_success '-c with changed comment char' '
        test_cmp expect actual
 '
 
+test_expect_success 'avoid SP-HT sequence in commented line' '
+       printf "#\tone\n#\n# two\n" >expect &&
+       printf "\tone\n\ntwo\n" | git stripspace -c >actual &&
+       test_cmp expect actual
+'
+
 test_done