aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-07-23 12:58:27 +0100
committerJunio C Hamano <gitster@pobox.com>2007-07-26 22:51:44 -0700
commitf653aee5a37b909e772d612eb7e226f09fd2f3d3 (patch)
tree0f4c571b9599721150db43ffcb87b085b83c2c30
parent2ae68fcb785a617793813abcea19893e13e436b0 (diff)
downloadgit-f653aee5a37b909e772d612eb7e226f09fd2f3d3.tar.gz
git-f653aee5a37b909e772d612eb7e226f09fd2f3d3.tar.xz
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>
-rw-r--r--Documentation/git-stripspace.txt5
-rw-r--r--builtin-stripspace.c7
-rwxr-xr-xt/t0030-stripspace.sh5
3 files changed, 15 insertions, 2 deletions
diff --git a/Documentation/git-stripspace.txt b/Documentation/git-stripspace.txt
index 1306d7bab..521235830 100644
--- a/Documentation/git-stripspace.txt
+++ b/Documentation/git-stripspace.txt
@@ -8,7 +8,7 @@ git-stripspace - Filter out empty lines
SYNOPSIS
--------
-'git-stripspace' < <stream>
+'git-stripspace' [-s | --strip-comments] < <stream>
DESCRIPTION
-----------
@@ -16,6 +16,9 @@ Remove multiple empty lines, and empty lines at beginning and end.
OPTIONS
-------
+-s\|--strip-comments::
+ In addition to empty lines, also strip lines starting with '#'.
+
<stream>::
Byte stream to act on.
diff --git a/builtin-stripspace.c b/builtin-stripspace.c
index 55716873d..916355ca5 100644
--- a/builtin-stripspace.c
+++ b/builtin-stripspace.c
@@ -76,6 +76,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
char *buffer;
unsigned long size;
+ int strip_comments = 0;
+
+ if (argc > 1 && (!strcmp(argv[1], "-s") ||
+ !strcmp(argv[1], "--strip-comments")))
+ strip_comments = 1;
size = 1024;
buffer = xmalloc(size);
@@ -84,7 +89,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
die("could not read the input");
}
- size = stripspace(buffer, size, 0);
+ size = stripspace(buffer, size, strip_comments);
write_or_die(1, buffer, size);
if (size)
putc('\n', stdout);
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index b1c900379..cad95f35a 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -392,4 +392,9 @@ test_expect_success \
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