builtin-tag: accept and process multiple -m just like git-commit
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 22, 2007 at 23:16 UTC
bd46c9a91261f282546a1a41b5303b041fae1361
2 files changed
+32
-9
Documentation/git-tag.txt
+3
-1
@@ -65,7 +65,9 @@ OPTIONS
65
Typing "git tag" without arguments, also lists all tags.
66
67
-m <msg>::
68
- Use the given tag message (instead of prompting)
68
+ Use the given tag message (instead of prompting).
69
+ If multiple `-m` options are given, there values are
70
+ concatenated as separate paragraphs.
71
72
-F <file>::
73
Take the tag message from the given file. Use '-' to
builtin-tag.c
+29
-8
@@ -282,7 +282,7 @@ static void write_tag_body(int fd, const unsigned char *sha1)
282
283
static void create_tag(const unsigned char *object, const char *tag,
284
struct strbuf *buf, int message, int sign,
285
- unsigned char *prev, unsigned char *result)
285
+ unsigned char *prev, unsigned char *result)
286
{
287
enum object_type type;
288
char header_buf[1024];
@@ -341,6 +341,24 @@ static void create_tag(const unsigned char *object, const char *tag,
341
die("unable to write tag file");
342
}
343
344
+struct msg_arg {
345
+ int given;
346
+ struct strbuf buf;
347
+};
348
+
349
+static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
350
+{
351
+ struct msg_arg *msg = opt->value;
352
+
353
+ if (!arg)
354
+ return -1;
355
+ if (msg->buf.len)
356
+ strbuf_addstr(&(msg->buf), "\n\n");
357
+ strbuf_addstr(&(msg->buf), arg);
358
+ msg->given = 1;
359
+ return 0;
360
+}
361
+
362
int cmd_tag(int argc, const char **argv, const char *prefix)
363
{
364
struct strbuf buf;
@@ -351,8 +369,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
369
370
int annotate = 0, sign = 0, force = 0, lines = 0,
371
delete = 0, verify = 0;
354
- char *list = NULL, *msg = NULL, *msgfile = NULL, *keyid = NULL;
372
+ char *list = NULL, *msgfile = NULL, *keyid = NULL;
373
const char *no_pattern = "NO_PATTERN";
374
+ struct msg_arg msg = { 0, STRBUF_INIT };
375
struct option options[] = {
376
{ OPTION_STRING, 'l', NULL, &list, "pattern", "list tag names",
377
PARSE_OPT_OPTARG, NULL, (intptr_t) no_pattern },
@@ -365,7 +384,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
384
OPT_GROUP("Tag creation options"),
385
OPT_BOOLEAN('a', NULL, &annotate,
386
"annotated tag, needs a message"),
368
- OPT_STRING('m', NULL, &msg, "msg", "message for the tag"),
387
+ OPT_CALLBACK('m', NULL, &msg, "msg",
388
+ "message for the tag", parse_msg_arg),
389
OPT_STRING('F', NULL, &msgfile, "file", "message in a file"),
390
OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
391
OPT_STRING('u', NULL, &keyid, "key-id",
@@ -386,12 +406,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
406
return for_each_tag_name(argv, verify_tag);
407
408
strbuf_init(&buf, 0);
389
- if (msg || msgfile) {
390
- if (msg && msgfile)
409
+ if (msg.given || msgfile) {
410
+ if (msg.given && msgfile)
411
die("only one -F or -m option is allowed.");
412
annotate = 1;
393
- if (msg)
394
- strbuf_addstr(&buf, msg);
413
+ if (msg.given)
414
+ strbuf_addbuf(&buf, &(msg.buf));
415
else {
416
if (!strcmp(msgfile, "-")) {
417
if (strbuf_read(&buf, 0, 1024) < 0)
@@ -429,7 +449,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
449
die("tag '%s' already exists", tag);
450
451
if (annotate)
432
- create_tag(object, tag, &buf, msg || msgfile, sign, prev, object);
452
+ create_tag(object, tag, &buf, msg.given || msgfile,
453
+ sign, prev, object);
454
455
lock = lock_any_ref_for_update(ref, prev, 0);
456
if (!lock)