@matheusbsbs / matheus-bagliano / commits / f653aee5a3
Fork 0

Teach "git stripspace" the --strip-comments option

With --strip-comments (or short -s), git stripspace now removes lines beginning with a '#', too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 23, 2007 at 12:58 UTC f653aee5a37b909e772d612eb7e226f09fd2f3d3
3 files changed +15 -2
Documentation/git-stripspace.txt
+4 -1
@@ -8,7 +8,7 @@ git-stripspace - Filter out empty lines
8
9 SYNOPSIS
10 --------
11 -'git-stripspace' < <stream>
11 +'git-stripspace' [-s | --strip-comments] < <stream>
12
13 DESCRIPTION
14 -----------
@@ -16,6 +16,9 @@ Remove multiple empty lines, and empty lines at beginning and end.
16
17 OPTIONS
18 -------
19 +-s\|--strip-comments::
20 + In addition to empty lines, also strip lines starting with '#'.
21 +
22 <stream>::
23 Byte stream to act on.
24
builtin-stripspace.c
+6 -1
@@ -76,6 +76,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
76 {
77 char *buffer;
78 unsigned long size;
79 + int strip_comments = 0;
80 +
81 + if (argc > 1 && (!strcmp(argv[1], "-s") ||
82 + !strcmp(argv[1], "--strip-comments")))
83 + strip_comments = 1;
84
85 size = 1024;
86 buffer = xmalloc(size);
@@ -84,7 +89,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
89 die("could not read the input");
90 }
91
87 - size = stripspace(buffer, size, 0);
92 + size = stripspace(buffer, size, strip_comments);
93 write_or_die(1, buffer, size);
94 if (size)
95 putc('\n', stdout);
t/t0030-stripspace.sh
+5
@@ -392,4 +392,9 @@ test_expect_success \
392 git diff expect actual
393 '
394
395 +test_expect_success 'strip comments, too' '
396 + test ! -z "$(echo "# comment" | git stripspace)" &&
397 + test -z "$(echo "# comment" | git stripspace -s)"
398 +'
399 +
400 test_done