]>
git.ipfire.org Git - thirdparty/git.git/blob - builtin/stripspace.c
5 #include "parse-options.h"
8 static void comment_lines(struct strbuf
*buf
)
13 msg
= strbuf_detach(buf
, &len
);
14 strbuf_add_commented_lines(buf
, msg
, len
);
18 static const char * const stripspace_usage
[] = {
19 "git stripspace [-s | --strip-comments]",
20 "git stripspace [-c | --comment-lines]",
24 enum stripspace_mode
{
30 int cmd_stripspace(int argc
, const char **argv
, const char *prefix
)
32 struct strbuf buf
= STRBUF_INIT
;
33 enum stripspace_mode mode
= STRIP_DEFAULT
;
36 const struct option options
[] = {
37 OPT_CMDMODE('s', "strip-comments", &mode
,
38 N_("skip and remove all lines starting with comment character"),
40 OPT_CMDMODE('c', "comment-lines", &mode
,
41 N_("prepend comment character and space to each line"),
46 argc
= parse_options(argc
, argv
, prefix
, options
, stripspace_usage
, 0);
48 usage_with_options(stripspace_usage
, options
);
50 if (mode
== STRIP_COMMENTS
|| mode
== COMMENT_LINES
) {
51 setup_git_directory_gently(&nongit
);
52 git_config(git_default_config
, NULL
);
55 if (strbuf_read(&buf
, 0, 1024) < 0)
56 die_errno("could not read the input");
58 if (mode
== STRIP_DEFAULT
|| mode
== STRIP_COMMENTS
)
59 strbuf_stripspace(&buf
, mode
== STRIP_COMMENTS
);
63 write_or_die(1, buf
.buf
, buf
.len
);