1 #define USE_THE_REPOSITORY_VARIABLE
4 #include "environment.h"
6 #include "parse-options.h"
9 #include "write-or-die.h"
11 static void comment_lines(struct strbuf
*buf
)
16 msg
= strbuf_detach(buf
, &len
);
17 strbuf_add_commented_lines(buf
, msg
, len
, comment_line_str
);
21 static const char * const stripspace_usage
[] = {
22 "git stripspace [-s | --strip-comments]",
23 "git stripspace [-c | --comment-lines]",
27 enum stripspace_mode
{
33 int cmd_stripspace(int argc
,
36 struct repository
*repo UNUSED
)
38 struct strbuf buf
= STRBUF_INIT
;
39 enum stripspace_mode mode
= STRIP_DEFAULT
;
42 const struct option options
[] = {
43 OPT_CMDMODE('s', "strip-comments", &mode
,
44 N_("skip and remove all lines starting with comment character"),
46 OPT_CMDMODE('c', "comment-lines", &mode
,
47 N_("prepend comment character and space to each line"),
52 argc
= parse_options(argc
, argv
, prefix
, options
, stripspace_usage
, 0);
54 usage_with_options(stripspace_usage
, options
);
56 if (mode
== STRIP_COMMENTS
|| mode
== COMMENT_LINES
) {
57 setup_git_directory_gently(&nongit
);
58 git_config(git_default_config
, NULL
);
61 if (strbuf_read(&buf
, 0, 1024) < 0)
62 die_errno("could not read the input");
64 if (mode
== STRIP_DEFAULT
|| mode
== STRIP_COMMENTS
)
65 strbuf_stripspace(&buf
,
66 mode
== STRIP_COMMENTS
? comment_line_str
: NULL
);
70 write_or_die(1, buf
.buf
, buf
.len
);