{"thread":{"id":"37456","subject":"[PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()","startedAt":"2014-08-30T16:14:24Z","lastAt":"2014-09-03T03:50:26Z","messageCount":3,"participants":["René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"248655","messageId":"5401F860.4030902@web.de","threadId":"37456","inReplyTo":null,"subject":"[PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-08-30T16:14:24Z","receivedAt":"2014-08-30T16:14:24Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use starts_with() instead of memcmp() to check if NUL-terminated\nstrings match prefixes.  This gets rid of some magic string length\nconstants.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n imap-send.c | 9 ++++++---\n 1 file changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 524fbab..b079a0d 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -524,7 +524,7 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,\n \tif (Verbose) {\n \t\tif (imap->num_in_progress)\n \t\t\tprintf(\"(%d in progress) \", imap->num_in_progress);\n-\t\tif (memcmp(cmd->cmd, \"LOGIN\", 5))\n+\t\tif (!starts_with(cmd->cmd, \"LOGIN\"))\n \t\t\tprintf(\">>> %s\", buf);\n \t\telse\n \t\t\tprintf(\">>> %d LOGIN <user> <pass>\\n\", cmd->tag);\n@@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n \t\t\t\tresp = DRV_OK;\n \t\t\telse {\n \t\t\t\tif (!strcmp(\"NO\", arg)) {\n-\t\t\t\t\tif (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, \"[TRYCREATE]\", 11))) { /* SELECT, APPEND or UID COPY */\n+\t\t\t\t\tif (cmdp->cb.create && cmd &&\n+\t\t\t\t\t    (cmdp->cb.trycreate ||\n+\t\t\t\t\t     starts_with(cmd, \"[TRYCREATE]\"))) {\n+\t\t\t\t\t\t/* SELECT, APPEND or UID COPY */\n \t\t\t\t\t\tp = strchr(cmdp->cmd, '\"');\n \t\t\t\t\t\tif (!issue_imap_cmd(ctx, NULL, \"CREATE \\\"%.*s\\\"\", (int)(strchr(p + 1, '\"') - p + 1), p)) {\n \t\t\t\t\t\t\tresp = RESP_BAD;\n@@ -827,7 +830,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n \t\t\t\t} else /*if (!strcmp(\"BAD\", arg))*/\n \t\t\t\t\tresp = RESP_BAD;\n \t\t\t\tfprintf(stderr, \"IMAP command '%s' returned response (%s) - %s\\n\",\n-\t\t\t\t\t memcmp(cmdp->cmd, \"LOGIN\", 5) ?\n+\t\t\t\t\t!starts_with(cmdp->cmd, \"LOGIN\") ?\n \t\t\t\t\t\t\tcmdp->cmd : \"LOGIN <user> <pass>\",\n \t\t\t\t\t\t\targ, cmd ? cmd : \"\");\n \t\t\t}\n-- \n2.1.0\n"},{"id":"248733","messageId":"xmqqoauxzv1f.fsf@gitster.dls.corp.google.com","threadId":"37456","inReplyTo":"5401F860.4030902@web.de","subject":"Re: [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-09-02T19:23:08Z","receivedAt":"2014-09-02T19:23:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Use starts_with() instead of memcmp() to check if NUL-terminated\n> strings match prefixes.  This gets rid of some magic string length\n> constants.\n>\n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n>  imap-send.c | 9 ++++++---\n>  1 file changed, 6 insertions(+), 3 deletions(-)\n>\n> diff --git a/imap-send.c b/imap-send.c\n> index 524fbab..b079a0d 100644\n> --- a/imap-send.c\n> +++ b/imap-send.c\n> @@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>  \t\t\t\tresp = DRV_OK;\n>  \t\t\telse {\n>  \t\t\t\tif (!strcmp(\"NO\", arg)) {\n> -\t\t\t\t\tif (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, \"[TRYCREATE]\", 11))) { /* SELECT, APPEND or UID COPY */\n> +\t\t\t\t\tif (cmdp->cb.create && cmd &&\n> +\t\t\t\t\t    (cmdp->cb.trycreate ||\n> +\t\t\t\t\t     starts_with(cmd, \"[TRYCREATE]\"))) {\n> +\t\t\t\t\t\t/* SELECT, APPEND or UID COPY */\n>  \t\t\t\t\t\tp = strchr(cmdp->cmd, '\"');\n>  \t\t\t\t\t\tif (!issue_imap_cmd(ctx, NULL, \"CREATE \\\"%.*s\\\"\", (int)(strchr(p + 1, '\"') - p + 1), p)) {\n>  \t\t\t\t\t\t\tresp = RESP_BAD;\n\nDo we want this hunk, given that it will disappear with the\ntf/imap-send-create topic at e0d8e308 (imap-send: create target\nmailbox if it is missing, 2014-08-01)?\n"},{"id":"248769","messageId":"54069002.5010404@web.de","threadId":"37456","inReplyTo":"xmqqoauxzv1f.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-09-03T03:50:26Z","receivedAt":"2014-09-03T03:50:26Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 02.09.2014 um 21:23 schrieb Junio C Hamano:\n> René Scharfe <l.s.r@web.de> writes:\n>\n>> Use starts_with() instead of memcmp() to check if NUL-terminated\n>> strings match prefixes.  This gets rid of some magic string length\n>> constants.\n>>\n>> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n>> ---\n>>   imap-send.c | 9 ++++++---\n>>   1 file changed, 6 insertions(+), 3 deletions(-)\n>>\n>> diff --git a/imap-send.c b/imap-send.c\n>> index 524fbab..b079a0d 100644\n>> --- a/imap-send.c\n>> +++ b/imap-send.c\n>> @@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>>   \t\t\t\tresp = DRV_OK;\n>>   \t\t\telse {\n>>   \t\t\t\tif (!strcmp(\"NO\", arg)) {\n>> -\t\t\t\t\tif (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, \"[TRYCREATE]\", 11))) { /* SELECT, APPEND or UID COPY */\n>> +\t\t\t\t\tif (cmdp->cb.create && cmd &&\n>> +\t\t\t\t\t    (cmdp->cb.trycreate ||\n>> +\t\t\t\t\t     starts_with(cmd, \"[TRYCREATE]\"))) {\n>> +\t\t\t\t\t\t/* SELECT, APPEND or UID COPY */\n>>   \t\t\t\t\t\tp = strchr(cmdp->cmd, '\"');\n>>   \t\t\t\t\t\tif (!issue_imap_cmd(ctx, NULL, \"CREATE \\\"%.*s\\\"\", (int)(strchr(p + 1, '\"') - p + 1), p)) {\n>>   \t\t\t\t\t\t\tresp = RESP_BAD;\n>\n> Do we want this hunk, given that it will disappear with the\n> tf/imap-send-create topic at e0d8e308 (imap-send: create target\n> mailbox if it is missing, 2014-08-01)?\n\nIn that case it's unnecessary; apparently I overlooked the conflicting \nhunk while preparing the patch for sending.\n\nRené\n"}]}