Skip to content

Commit 4e35c51

Browse files
arachsysgitster
authored andcommitted
whitespace: add tab-in-indent support for --whitespace=fix
If tab-in-indent is set, --whitespace=fix will ensure that any stray tabs in the initial indent are expanded to the correct number of space characters. Signed-off-by: Chris Webb <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d511bd3 commit 4e35c51

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ws.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,20 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule,
360360
len -= last;
361361
src += last;
362362
fixed = 1;
363+
} else if ((ws_rule & WS_TAB_IN_INDENT) && last_tab_in_indent >= 0) {
364+
/* Expand tabs into spaces */
365+
int last = last_tab_in_indent + 1;
366+
for (i = 0; i < last; i++) {
367+
if (src[i] == '\t')
368+
do {
369+
strbuf_addch(dst, ' ');
370+
} while (dst->len % 8);
371+
else
372+
strbuf_addch(dst, src[i]);
373+
}
374+
len -= last;
375+
src += last;
376+
fixed = 1;
363377
}
364378

365379
strbuf_add(dst, src, len);

0 commit comments

Comments
 (0)