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>
This commit is contained in:

committed by
Junio C Hamano

parent
2ae68fcb78
commit
f653aee5a3
@ -8,7 +8,7 @@ git-stripspace - Filter out empty lines
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git-stripspace' < <stream>
|
'git-stripspace' [-s | --strip-comments] < <stream>
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@ -16,6 +16,9 @@ Remove multiple empty lines, and empty lines at beginning and end.
|
|||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-------
|
-------
|
||||||
|
-s\|--strip-comments::
|
||||||
|
In addition to empty lines, also strip lines starting with '#'.
|
||||||
|
|
||||||
<stream>::
|
<stream>::
|
||||||
Byte stream to act on.
|
Byte stream to act on.
|
||||||
|
|
||||||
|
@ -76,6 +76,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
|
|||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
int strip_comments = 0;
|
||||||
|
|
||||||
|
if (argc > 1 && (!strcmp(argv[1], "-s") ||
|
||||||
|
!strcmp(argv[1], "--strip-comments")))
|
||||||
|
strip_comments = 1;
|
||||||
|
|
||||||
size = 1024;
|
size = 1024;
|
||||||
buffer = xmalloc(size);
|
buffer = xmalloc(size);
|
||||||
@ -84,7 +89,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
|
|||||||
die("could not read the input");
|
die("could not read the input");
|
||||||
}
|
}
|
||||||
|
|
||||||
size = stripspace(buffer, size, 0);
|
size = stripspace(buffer, size, strip_comments);
|
||||||
write_or_die(1, buffer, size);
|
write_or_die(1, buffer, size);
|
||||||
if (size)
|
if (size)
|
||||||
putc('\n', stdout);
|
putc('\n', stdout);
|
||||||
|
@ -392,4 +392,9 @@ test_expect_success \
|
|||||||
git diff expect actual
|
git diff expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'strip comments, too' '
|
||||||
|
test ! -z "$(echo "# comment" | git stripspace)" &&
|
||||||
|
test -z "$(echo "# comment" | git stripspace -s)"
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user