{"thread":{"id":"29076","subject":"[PATCH, v3] git-tag: introduce --[no-]strip options","startedAt":"2011-12-03T17:12:56Z","lastAt":"2011-12-03T20:04:28Z","messageCount":2,"participants":["Kirill A. Shutemov","Jeff King"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"180282","messageId":"1322932376-15720-1-git-send-email-kirill@shutemov.name","threadId":"29076","inReplyTo":null,"subject":"[PATCH, v3] git-tag: introduce --[no-]strip options","fromName":"Kirill A. Shutemov","fromEmail":"kirill@shutemov.name","sentAt":"2011-12-03T17:12:56Z","receivedAt":"2011-12-03T17:12:56Z","isPatch":true,"sender":{"key":"kirill@shutemov.name","avatar":"https://avatars.githubusercontent.com/u/588661?v=4"},"body":"From: \"Kirill A. Shutemov\" <kirill@shutemov.name>\n\nNormally git tag stripes tag message lines starting with '#', trailing\nspaces from every line and empty lines from the beginning and end.\n\n--no-strip is useful if you want to take a tag message as-is, without\nany stripping.\n\nSigned-off-by: Kirill A. Shutemov <kirill@shutemov.name>\n---\n Documentation/git-tag.txt |    6 ++++++\n builtin/tag.c             |   41 +++++++++++++++++++++++++++--------------\n 2 files changed, 33 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt\nindex c83cb13..31463ca 100644\n--- a/Documentation/git-tag.txt\n+++ b/Documentation/git-tag.txt\n@@ -99,6 +99,12 @@ OPTIONS\n \tImplies `-a` if none of `-a`, `-s`, or `-u <key-id>`\n \tis given.\n \n+--strip::\n+\tRemove from tag message lines starting with '#', trailing spaces from\n+\tevery line and empty lines from the beginning and end.  Enabled by\n+\tdefault. With `--no-strip`, the tag message given by the user is used\n+\tas-is.\n+\n <tagname>::\n \tThe name of the tag to create, delete, or describe.\n \tThe new tag name must pass all checks defined by\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 9b6fd95..d82774d 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -319,8 +319,14 @@ static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)\n \treturn 0;\n }\n \n+struct create_tag_options {\n+\tunsigned int message;\n+\tunsigned int sign;\n+\tunsigned int strip;\n+};\n+\n static void create_tag(const unsigned char *object, const char *tag,\n-\t\t       struct strbuf *buf, int message, int sign,\n+\t\t       struct strbuf *buf, struct create_tag_options *opt,\n \t\t       unsigned char *prev, unsigned char *result)\n {\n \tenum object_type type;\n@@ -345,7 +351,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \tif (header_len > sizeof(header_buf) - 1)\n \t\tdie(_(\"tag header too big.\"));\n \n-\tif (!message) {\n+\tif (!opt->message) {\n \t\tint fd;\n \n \t\t/* write the template message before editing: */\n@@ -356,7 +362,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \n \t\tif (!is_null_sha1(prev))\n \t\t\twrite_tag_body(fd, prev);\n-\t\telse\n+\t\telse if (opt->strip)\n \t\t\twrite_or_die(fd, _(tag_template), strlen(_(tag_template)));\n \t\tclose(fd);\n \n@@ -367,14 +373,15 @@ static void create_tag(const unsigned char *object, const char *tag,\n \t\t}\n \t}\n \n-\tstripspace(buf, 1);\n+\tif (opt->strip)\n+\t\tstripspace(buf, 1);\n \n-\tif (!message && !buf->len)\n+\tif (opt->message && !buf->len)\n \t\tdie(_(\"no tag message?\"));\n \n \tstrbuf_insert(buf, 0, header_buf, header_len);\n \n-\tif (build_tag_object(buf, sign, result) < 0) {\n+\tif (build_tag_object(buf, opt->sign, result) < 0) {\n \t\tif (path)\n \t\t\tfprintf(stderr, _(\"The tag message has been left in %s\\n\"),\n \t\t\t\tpath);\n@@ -422,9 +429,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tunsigned char object[20], prev[20];\n \tconst char *object_ref, *tag;\n \tstruct ref_lock *lock;\n-\n-\tint annotate = 0, sign = 0, force = 0, lines = -1,\n-\t\tlist = 0, delete = 0, verify = 0;\n+\tstruct create_tag_options opt;\n+\tint annotate = 0, force = 0, lines = -1, list = 0,\n+\t    delete = 0, verify = 0;\n \tconst char *msgfile = NULL, *keyid = NULL;\n \tstruct msg_arg msg = { 0, STRBUF_INIT };\n \tstruct commit_list *with_commit = NULL;\n@@ -442,7 +449,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\tOPT_CALLBACK('m', \"message\", &msg, \"message\",\n \t\t\t     \"tag message\", parse_msg_arg),\n \t\tOPT_FILENAME('F', \"file\", &msgfile, \"read message from file\"),\n-\t\tOPT_BOOLEAN('s', \"sign\", &sign, \"annotated and GPG-signed tag\"),\n+\t\tOPT_BOOLEAN('s', \"sign\", &opt.sign, \"annotated and GPG-signed tag\"),\n+\t\tOPT_BOOLEAN(0, \"strip\", &opt.strip,\n+\t\t\t\t\t\"turn off tag message stripping\"),\n \t\tOPT_STRING('u', \"local-user\", &keyid, \"key-id\",\n \t\t\t\t\t\"use another key to sign the tag\"),\n \t\tOPT__FORCE(&force, \"replace the tag if exists\"),\n@@ -459,13 +468,16 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_tag_config, NULL);\n \n+\topt.sign = 0;\n+\topt.strip = 1;\n+\n \targc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);\n \n \tif (keyid) {\n-\t\tsign = 1;\n+\t\topt.sign = 1;\n \t\tset_signingkey(keyid);\n \t}\n-\tif (sign)\n+\tif (opt.sign)\n \t\tannotate = 1;\n \tif (argc == 0 && !(delete || verify))\n \t\tlist = 1;\n@@ -523,9 +535,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \telse if (!force)\n \t\tdie(_(\"tag '%s' already exists\"), tag);\n \n+\topt.message = msg.given || msgfile;\n+\n \tif (annotate)\n-\t\tcreate_tag(object, tag, &buf, msg.given || msgfile,\n-\t\t\t   sign, prev, object);\n+\t\tcreate_tag(object, tag, &buf, &opt, prev, object);\n \n \tlock = lock_any_ref_for_update(ref.buf, prev, 0);\n \tif (!lock)\n-- \n1.7.7.3\n"},{"id":"180284","messageId":"20111203200428.GB6207@sigill.intra.peff.net","threadId":"29076","inReplyTo":"1322932376-15720-1-git-send-email-kirill@shutemov.name","subject":"Re: [PATCH, v3] git-tag: introduce --[no-]strip options","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-03T20:04:28Z","receivedAt":"2011-12-03T20:04:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Dec 03, 2011 at 07:12:56PM +0200, Kirill A. Shutemov wrote:\n\n> From: \"Kirill A. Shutemov\" <kirill@shutemov.name>\n> \n> Normally git tag stripes tag message lines starting with '#', trailing\n> spaces from every line and empty lines from the beginning and end.\n> \n> --no-strip is useful if you want to take a tag message as-is, without\n> any stripping.\n\nPerhaps this should mirror the \"--clean\" option from git-commit, as they\nare basically doing the same thing? Besides the name difference, --clean\nsupports three modes: verbatim, whitespace, and strip. And defaults to\nstrip or whitespace depending on whether we are actually writing into\nthe editor.\n\n-Peff\n"}]}