{"thread":{"id":"18250","subject":"[PATCH] builtin-tag.c: remove global variable to use the callback data of git-config.","startedAt":"2009-03-10T13:03:39Z","lastAt":"2009-03-10T16:36:56Z","messageCount":4,"participants":["Carlos Rica","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"107574","messageId":"1236690219.20402.28.camel@luis-desktop","threadId":"18250","inReplyTo":null,"subject":"[PATCH] builtin-tag.c: remove global variable to use the callback data of git-config.","fromName":"Carlos Rica","fromEmail":"jasampler@gmail.com","sentAt":"2009-03-10T13:03:39Z","receivedAt":"2009-03-10T13:03:39Z","isPatch":true,"sender":{"key":"jasampler@gmail.com","avatar":null},"body":"\nSigned-off-by: Carlos Rica <jasampler@yahoo.es>\n---\n\nThis way the data flow is much clearer.\n\nHere I declare a struct to wrap the new local array along with its size.\nAn alternative to this is strbuf, would it be preferable?\n\n builtin-tag.c |   43 ++++++++++++++++++++++++++-----------------\n 1 files changed, 26 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex 01e7374..2b2d728 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -21,8 +21,6 @@ static const char * const git_tag_usage[] = {\n \tNULL\n };\n \n-static char signingkey[1000];\n-\n struct tag_filter {\n \tconst char *pattern;\n \tint lines;\n@@ -156,7 +154,12 @@ static int verify_tag(const char *name, const char\n*ref,\n \treturn 0;\n }\n \n-static int do_sign(struct strbuf *buffer)\n+struct char_array {\n+\tchar *buf;\n+\tsize_t size;\n+};\n+\n+static int do_sign(struct char_array *signingkey, struct strbuf\n*buffer)\n {\n \tstruct child_process gpg;\n \tconst char *args[4];\n@@ -164,11 +167,12 @@ static int do_sign(struct strbuf *buffer)\n \tint len;\n \tint i, j;\n \n-\tif (!*signingkey) {\n-\t\tif (strlcpy(signingkey, git_committer_info(IDENT_ERROR_ON_NO_NAME),\n-\t\t\t\tsizeof(signingkey)) > sizeof(signingkey) - 1)\n+\tif (!signingkey->buf[0]) {\n+\t\tif (strlcpy(signingkey->buf,\n+\t\t\t\tgit_committer_info(IDENT_ERROR_ON_NO_NAME),\n+\t\t\t\tsigningkey->size) > signingkey->size - 1)\n \t\t\treturn error(\"committer info too long.\");\n-\t\tbracket = strchr(signingkey, '>');\n+\t\tbracket = strchr(signingkey->buf, '>');\n \t\tif (bracket)\n \t\t\tbracket[1] = '\\0';\n \t}\n@@ -183,7 +187,7 @@ static int do_sign(struct strbuf *buffer)\n \tgpg.out = -1;\n \targs[0] = \"gpg\";\n \targs[1] = \"-bsau\";\n-\targs[2] = signingkey;\n+\targs[2] = signingkey->buf;\n \targs[3] = NULL;\n \n \tif (start_command(&gpg))\n@@ -220,9 +224,10 @@ static const char tag_template[] =\n \t\"# Write a tag message\\n\"\n \t\"#\\n\";\n \n-static void set_signingkey(const char *value)\n+static void set_signingkey(struct char_array *signingkey, const char\n*value)\n {\n-\tif (strlcpy(signingkey, value, sizeof(signingkey)) >=\nsizeof(signingkey))\n+\tif (strlcpy(signingkey->buf, value, signingkey->size)\n+\t\t\t\t\t>= signingkey->size)\n \t\tdie(\"signing key value too long (%.10s...)\", value);\n }\n \n@@ -231,7 +236,7 @@ static int git_tag_config(const char *var, const\nchar *value, void *cb)\n \tif (!strcmp(var, \"user.signingkey\")) {\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\n-\t\tset_signingkey(value);\n+\t\tset_signingkey((struct char_array *) cb, value);\n \t\treturn 0;\n \t}\n \n@@ -266,9 +271,10 @@ static void write_tag_body(int fd, const unsigned\nchar *sha1)\n \tfree(buf);\n }\n \n-static int build_tag_object(struct strbuf *buf, int sign, unsigned char\n*result)\n+static int build_tag_object(struct strbuf *buf, int sign,\n+\t\t\tstruct char_array *signingkey, unsigned char *result)\n {\n-\tif (sign && do_sign(buf) < 0)\n+\tif (sign && do_sign(signingkey, buf) < 0)\n \t\treturn error(\"unable to sign the tag\");\n \tif (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)\n \t\treturn error(\"unable to write tag file\");\n@@ -277,6 +283,7 @@ static int build_tag_object(struct strbuf *buf, int\nsign, unsigned char *result)\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 char_array *signingkey,\n \t\t       unsigned char *prev, unsigned char *result)\n {\n \tenum object_type type;\n@@ -331,7 +338,7 @@ static void create_tag(const unsigned char *object,\nconst char *tag,\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, sign, signingkey, 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@@ -374,6 +381,8 @@ int cmd_tag(int argc, const char **argv, const char\n*prefix)\n \tconst char *msgfile = NULL, *keyid = NULL;\n \tstruct msg_arg msg = { 0, STRBUF_INIT };\n \tstruct commit_list *with_commit = NULL;\n+\tchar keyarr[1000] = {'\\0'};\n+\tstruct char_array signingkey = { keyarr, sizeof(keyarr) };\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN('l', NULL, &list, \"list tag names\"),\n \t\t{ OPTION_INTEGER, 'n', NULL, &lines, NULL,\n@@ -403,14 +412,14 @@ int cmd_tag(int argc, const char **argv, const\nchar *prefix)\n \t\tOPT_END()\n \t};\n \n-\tgit_config(git_tag_config, NULL);\n+\tgit_config(git_tag_config, &signingkey);\n \n \targc = parse_options(argc, argv, options, git_tag_usage, 0);\n \tmsgfile = parse_options_fix_filename(prefix, msgfile);\n \n \tif (keyid) {\n \t\tsign = 1;\n-\t\tset_signingkey(keyid);\n+\t\tset_signingkey(&signingkey, keyid);\n \t}\n \tif (sign)\n \t\tannotate = 1;\n@@ -474,7 +483,7 @@ int cmd_tag(int argc, const char **argv, const char\n*prefix)\n \n \tif (annotate)\n \t\tcreate_tag(object, tag, &buf, msg.given || msgfile,\n-\t\t\t   sign, prev, object);\n+\t\t\t   sign, &signingkey, prev, object);\n \n \tlock = lock_any_ref_for_update(ref, prev, 0);\n \tif (!lock)\n-- \n1.5.4.3\n"},{"id":"107575","messageId":"alpine.DEB.1.00.0903101432010.14295@intel-tinevez-2-302","threadId":"18250","inReplyTo":"1236690219.20402.28.camel@luis-desktop","subject":"Re: [PATCH] builtin-tag.c: remove global variable to use the callback data of git-config.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-10T13:34:20Z","receivedAt":"2009-03-10T13:34:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 10 Mar 2009, Carlos Rica wrote:\n\n> \n> Signed-off-by: Carlos Rica <jasampler@yahoo.es>\n\nGood to see you again!\n\nBTW do you want to be recorded with a different email address in the \nauthor line than in the S-O-B?\n\n> -static int do_sign(struct strbuf *buffer)\n> +struct char_array {\n> +\tchar *buf;\n> +\tsize_t size;\n> +};\n\nThat looks very much like you want a struct strbuf, no?\n\nCiao,\nDscho\n"},{"id":"107576","messageId":"1b46aba20903100700ob46a797lcf600e0ae868a35f@mail.gmail.com","threadId":"18250","inReplyTo":"alpine.DEB.1.00.0903101432010.14295@intel-tinevez-2-302","subject":"Re: [PATCH] builtin-tag.c: remove global variable to use the callback data of git-config.","fromName":"Carlos Rica","fromEmail":"jasampler@gmail.com","sentAt":"2009-03-10T14:00:55Z","receivedAt":"2009-03-10T14:00:55Z","isPatch":true,"sender":{"key":"jasampler@gmail.com","avatar":null},"body":"Please, don't even try to apply this patch, since long lines are wrapped.\n\nI will send it fixed, sorry by the inconvenience.\n\nOn Tue, Mar 10, 2009 at 2:34 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Tue, 10 Mar 2009, Carlos Rica wrote:\n>\n>>\n>> Signed-off-by: Carlos Rica <jasampler@yahoo.es>\n>\n> Good to see you again!\n\nThanks!\n>\n> BTW do you want to be recorded with a different email address in the\n> author line than in the S-O-B?\n\nThank you for notify it, Johannes! That's was another mistake here,\nI wanted to use the gmail account for this, I will change it when I\nsend this fixed.\n\n>> -static int do_sign(struct strbuf *buffer)\n>> +struct char_array {\n>> +     char *buf;\n>> +     size_t size;\n>> +};\n>\n> That looks very much like you want a struct strbuf, no?\n\nI was asking exactly that, in the hidden lines of the patch,\nso if everybody prefers the strbuf solution I will use it, and then,\nwe should choose if there must be a limit for the signing key id max length\n(now 1000) since by using dynamic memory it would not be required.\n\n> Ciao,\n> Dscho\n>\n>\n"},{"id":"107592","messageId":"7vzlft8hcn.fsf@gitster.siamese.dyndns.org","threadId":"18250","inReplyTo":"1236690219.20402.28.camel@luis-desktop","subject":"Re: [PATCH] builtin-tag.c: remove global variable to use the callback data of git-config.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-10T16:36:56Z","receivedAt":"2009-03-10T16:36:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carlos Rica <jasampler@gmail.com> writes:\n\n> Signed-off-by: Carlos Rica <jasampler@yahoo.es>\n> ---\n>\n> This way the data flow is much clearer.\n\nGood.  I think the Subject is backwards, though.\n"}]}