Skip to content

Commit

Permalink
Merge branch 'jc/strbuf-add-lines-avoid-sp-ht-sequence'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Jan 7, 2015
2 parents f41157e + d55aeb7 commit 58e0362
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion strbuf.c
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions t/t0030-stripspace.sh
Expand Up @@ -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

0 comments on commit 58e0362

Please sign in to comment.