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 <chris@arachsys.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chris Webb committed
Apr 3, 2010 at 00:37 UTC
4e35c51e5113e83155a6c44a8f9adeafed9125d2
1 file changed
+14
ws.c
+14
@@ -360,6 +360,20 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule,
360
len -= last;
361
src += last;
362
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;
377
}
378
379
strbuf_add(dst, src, len);