Skip to content

Commit f653aee

Browse files
dschogitster
authored andcommitted
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>
1 parent 2ae68fc commit f653aee

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Documentation/git-stripspace.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ git-stripspace - Filter out empty lines
88

99
SYNOPSIS
1010
--------
11-
'git-stripspace' < <stream>
11+
'git-stripspace' [-s | --strip-comments] < <stream>
1212

1313
DESCRIPTION
1414
-----------
1515
Remove multiple empty lines, and empty lines at beginning and end.
1616

1717
OPTIONS
1818
-------
19+
-s\|--strip-comments::
20+
In addition to empty lines, also strip lines starting with '#'.
21+
1922
<stream>::
2023
Byte stream to act on.
2124

builtin-stripspace.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
7676
{
7777
char *buffer;
7878
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;
7984

8085
size = 1024;
8186
buffer = xmalloc(size);
@@ -84,7 +89,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
8489
die("could not read the input");
8590
}
8691

87-
size = stripspace(buffer, size, 0);
92+
size = stripspace(buffer, size, strip_comments);
8893
write_or_die(1, buffer, size);
8994
if (size)
9095
putc('\n', stdout);

t/t0030-stripspace.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,9 @@ test_expect_success \
392392
git diff expect actual
393393
'
394394

395+
test_expect_success 'strip comments, too' '
396+
test ! -z "$(echo "# comment" | git stripspace)" &&
397+
test -z "$(echo "# comment" | git stripspace -s)"
398+
'
399+
395400
test_done

0 commit comments

Comments
 (0)