@matheusbsbs / matheus-bagliano / commits / f9568530c9
Fork 0

builtin-commit: resurrect behavior for multiple -m options

When more than one -m option is given, the message does not replace the previous, but is appended as a new paragraph. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 11, 2007 at 17:36 UTC f9568530c97757d840171c685fd623e1f68bc552
1 file changed +20 -6
builtin-commit.c
+20 -6
@@ -30,13 +30,27 @@ static char *use_message_buffer;
30 static const char commit_editmsg[] = "COMMIT_EDITMSG";
31 static struct lock_file lock_file;
32
33 -static char *logfile, *force_author, *message, *template_file;
33 +static char *logfile, *force_author, *template_file;
34 static char *edit_message, *use_message;
35 static int all, edit_flag, also, interactive, only, amend, signoff;
36 static int quiet, verbose, untracked_files, no_verify;
37
38 static int no_edit, initial_commit, in_merge;
39 const char *only_include_assumed;
40 +struct strbuf message;
41 +
42 +static int opt_parse_m(const struct option *opt, const char *arg, int unset)
43 +{
44 + struct strbuf *buf = opt->value;
45 + if (unset)
46 + strbuf_setlen(buf, 0);
47 + else {
48 + strbuf_addstr(buf, arg);
49 + strbuf_addch(buf, '\n');
50 + strbuf_addch(buf, '\n');
51 + }
52 + return 0;
53 +}
54
55 static struct option builtin_commit_options[] = {
56 OPT__QUIET(&quiet),
@@ -45,7 +59,7 @@ static struct option builtin_commit_options[] = {
59
60 OPT_STRING('F', "file", &logfile, "FILE", "read log from file"),
61 OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
48 - OPT_STRING('m', "message", &message, "MESSAGE", "specify commit message"),
62 + OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
63 OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "),
64 OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
65 OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by: header"),
@@ -150,8 +164,8 @@ static int prepare_log_message(const char *index_file, const char *prefix)
164 FILE *fp;
165
166 strbuf_init(&sb, 0);
153 - if (message) {
154 - strbuf_add(&sb, message, strlen(message));
167 + if (message.len) {
168 + strbuf_addbuf(&sb, &message);
169 } else if (logfile && !strcmp(logfile, "-")) {
170 if (isatty(0))
171 fprintf(stderr, "(reading log message from standard input)\n");
@@ -322,7 +336,7 @@ static int parse_and_validate_options(int argc, const char *argv[])
336 argc = parse_options(argc, argv, builtin_commit_options,
337 builtin_commit_usage, 0);
338
325 - if (logfile || message || use_message)
339 + if (logfile || message.len || use_message)
340 no_edit = 1;
341 if (edit_flag)
342 no_edit = 0;
@@ -347,7 +361,7 @@ static int parse_and_validate_options(int argc, const char *argv[])
361 f++;
362 if (f > 1)
363 die("Only one of -c/-C/-F can be used.");
350 - if (message && f > 0)
364 + if (message.len && f > 0)
365 die("Option -m cannot be combined with -c/-C/-F.");
366 if (edit_message)
367 use_message = edit_message;