{"thread":{"id":"36215","subject":"[PATCH v5] use starts_with() instead of !memcmp()","startedAt":"2014-03-19T01:18:02Z","lastAt":"2014-03-21T18:05:07Z","messageCount":5,"participants":["Quint Guvernator","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"237031","messageId":"1395191883-42409-1-git-send-email-quintus.public@gmail.com","threadId":"36215","inReplyTo":null,"subject":"[PATCH v5] use starts_with() instead of !memcmp()","fromName":"Quint Guvernator","fromEmail":"quintus.public@gmail.com","sentAt":"2014-03-19T01:18:02Z","receivedAt":"2014-03-19T01:18:02Z","isPatch":true,"sender":{"key":"quintus.public@gmail.com","avatar":"https://gravatar.com/avatar/0805695585d6191e00badd5057b262b501047d9fb2b22dd2495009ffb25d85fd?d=mp&s=160"},"body":"Another version, this time very in line with the review and commentary of\nJunio, Eric, and Michael.  This version boasts a revamped commit message and\nfewer but surer hunks changed.\n\nThanks again for the guidance.\n\nQuint Guvernator (1):\n  use starts_with() instead of !memcmp()\n\n builtin/apply.c        |  4 ++--\n builtin/for-each-ref.c |  2 +-\n builtin/mktag.c        |  2 +-\n builtin/patch-id.c     | 10 +++++-----\n connect.c              |  4 ++--\n imap-send.c            |  6 +++---\n remote.c               |  2 +-\n 7 files changed, 15 insertions(+), 15 deletions(-)\n\n-- \n1.9.0\n"},{"id":"237032","messageId":"1395191883-42409-2-git-send-email-quintus.public@gmail.com","threadId":"36215","inReplyTo":"1395191883-42409-1-git-send-email-quintus.public@gmail.com","subject":"[PATCH v5] use starts_with() instead of !memcmp()","fromName":"Quint Guvernator","fromEmail":"quintus.public@gmail.com","sentAt":"2014-03-19T01:18:03Z","receivedAt":"2014-03-19T01:18:03Z","isPatch":true,"sender":{"key":"quintus.public@gmail.com","avatar":"https://gravatar.com/avatar/0805695585d6191e00badd5057b262b501047d9fb2b22dd2495009ffb25d85fd?d=mp&s=160"},"body":"When checking if a string begins with a constant string, using\nstarts_with() indicates the intention of the check more clearly and is\nless error-prone than calling !memcmp() with an explicit byte count.\n\nSigned-off-by: Quint Guvernator <quintus.public@gmail.com>\n---\n builtin/apply.c        |  4 ++--\n builtin/for-each-ref.c |  2 +-\n builtin/mktag.c        |  2 +-\n builtin/patch-id.c     | 10 +++++-----\n connect.c              |  4 ++--\n imap-send.c            |  6 +++---\n remote.c               |  2 +-\n 7 files changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 0189523..826b3e2 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1631,7 +1631,7 @@ static int parse_fragment(const char *line, unsigned long size,\n \t\t * l10n of \"\\ No newline...\" is at least that long.\n \t\t */\n \t\tcase '\\\\':\n-\t\t\tif (len < 12 || memcmp(line, \"\\\\ \", 2))\n+\t\t\tif (len < 12 || !starts_with(line, \"\\\\ \"))\n \t\t\t\treturn -1;\n \t\t\tbreak;\n \t\t}\n@@ -1646,7 +1646,7 @@ static int parse_fragment(const char *line, unsigned long size,\n \t * it in the above loop because we hit oldlines == newlines == 0\n \t * before seeing it.\n \t */\n-\tif (12 < size && !memcmp(line, \"\\\\ \", 2))\n+\tif (12 < size && starts_with(line, \"\\\\ \"))\n \t\toffset += linelen(line, size);\n \n \tpatch->lines_added += added;\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 3e1d5c3..4135980 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -193,7 +193,7 @@ static int verify_format(const char *format)\n \t\tat = parse_atom(sp + 2, ep);\n \t\tcp = ep + 1;\n \n-\t\tif (!memcmp(used_atom[at], \"color:\", 6))\n+\t\tif (starts_with(used_atom[at], \"color:\"))\n \t\t\tneed_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);\n \t}\n \treturn 0;\ndiff --git a/builtin/mktag.c b/builtin/mktag.c\nindex 640ab64..d2d9310 100644\n--- a/builtin/mktag.c\n+++ b/builtin/mktag.c\n@@ -57,7 +57,7 @@ static int verify_tag(char *buffer, unsigned long size)\n \n \t/* Verify type line */\n \ttype_line = object + 48;\n-\tif (memcmp(type_line - 1, \"\\ntype \", 6))\n+\tif (!starts_with(type_line - 1, \"\\ntype \"))\n \t\treturn error(\"char%d: could not find \\\"\\\\ntype \\\"\", 47);\n \n \t/* Verify tag-line */\ndiff --git a/builtin/patch-id.c b/builtin/patch-id.c\nindex 3cfe02d..23ef424 100644\n--- a/builtin/patch-id.c\n+++ b/builtin/patch-id.c\n@@ -81,14 +81,14 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st\n \t\t}\n \n \t\t/* Ignore commit comments */\n-\t\tif (!patchlen && memcmp(line, \"diff \", 5))\n+\t\tif (!patchlen && !starts_with(line, \"diff \"))\n \t\t\tcontinue;\n \n \t\t/* Parsing diff header?  */\n \t\tif (before == -1) {\n-\t\t\tif (!memcmp(line, \"index \", 6))\n+\t\t\tif (starts_with(line, \"index \"))\n \t\t\t\tcontinue;\n-\t\t\telse if (!memcmp(line, \"--- \", 4))\n+\t\t\telse if (starts_with(line, \"--- \"))\n \t\t\t\tbefore = after = 1;\n \t\t\telse if (!isalpha(line[0]))\n \t\t\t\tbreak;\n@@ -96,14 +96,14 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st\n \n \t\t/* Looking for a valid hunk header?  */\n \t\tif (before == 0 && after == 0) {\n-\t\t\tif (!memcmp(line, \"@@ -\", 4)) {\n+\t\t\tif (starts_with(line, \"@@ -\")) {\n \t\t\t\t/* Parse next hunk, but ignore line numbers.  */\n \t\t\t\tscan_hunk_header(line, &before, &after);\n \t\t\t\tcontinue;\n \t\t\t}\n \n \t\t\t/* Split at the end of the patch.  */\n-\t\t\tif (memcmp(line, \"diff \", 5))\n+\t\t\tif (!starts_with(line, \"diff \"))\n \t\t\t\tbreak;\n \n \t\t\t/* Else we're parsing another header.  */\ndiff --git a/connect.c b/connect.c\nindex 4150412..5ae2aaa 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -30,11 +30,11 @@ static int check_ref(const char *name, int len, unsigned int flags)\n \t\treturn 0;\n \n \t/* REF_HEADS means that we want regular branch heads */\n-\tif ((flags & REF_HEADS) && !memcmp(name, \"heads/\", 6))\n+\tif ((flags & REF_HEADS) && starts_with(name, \"heads/\"))\n \t\treturn 1;\n \n \t/* REF_TAGS means that we want tags */\n-\tif ((flags & REF_TAGS) && !memcmp(name, \"tags/\", 5))\n+\tif ((flags & REF_TAGS) && starts_with(name, \"tags/\"))\n \t\treturn 1;\n \n \t/* All type bits clear means that we are ok with anything */\ndiff --git a/imap-send.c b/imap-send.c\nindex 0bc6f7f..019de18 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,7 @@ 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 && (cmdp->cb.trycreate || starts_with(cmd, \"[TRYCREATE]\"))) { /* 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 +827,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}\ndiff --git a/remote.c b/remote.c\nindex 5f63d55..bd02b0e 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1149,7 +1149,7 @@ static int match_explicit(struct ref *src, struct ref *dst,\n \tcase 1:\n \t\tbreak;\n \tcase 0:\n-\t\tif (!memcmp(dst_value, \"refs/\", 5))\n+\t\tif (starts_with(dst_value, \"refs/\"))\n \t\t\tmatched_dst = make_linked_ref(dst_value, dst_tail);\n \t\telse if (is_null_sha1(matched_src->new_sha1))\n \t\t\terror(\"unable to delete '%s': remote ref does not exist\",\n-- \n1.9.0\n"},{"id":"237039","messageId":"CAPig+cTWV0PWOh88u+rbMPvnn3O+OhTJATEtXXi4oLKUN25Ezw@mail.gmail.com","threadId":"36215","inReplyTo":"1395191883-42409-1-git-send-email-quintus.public@gmail.com","subject":"Re: [PATCH v5] use starts_with() instead of !memcmp()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-19T04:13:13Z","receivedAt":"2014-03-19T04:13:13Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Mar 18, 2014 at 9:18 PM, Quint Guvernator\n<quintus.public@gmail.com> wrote:\n> Another version, this time very in line with the review and commentary of\n> Junio, Eric, and Michael.  This version boasts a revamped commit message and\n> fewer but surer hunks changed.\n\nExplaining what changed in this version is indeed a courtesy to\nreviewers. Thanks.\n\nFor bonus points, provide a link to the previous attempt, like this [1].\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/244292\n\n> Thanks again for the guidance.\n>\n> Quint Guvernator (1):\n>   use starts_with() instead of !memcmp()\n>\n>  builtin/apply.c        |  4 ++--\n>  builtin/for-each-ref.c |  2 +-\n>  builtin/mktag.c        |  2 +-\n>  builtin/patch-id.c     | 10 +++++-----\n>  connect.c              |  4 ++--\n>  imap-send.c            |  6 +++---\n>  remote.c               |  2 +-\n>  7 files changed, 15 insertions(+), 15 deletions(-)\n>\n> --\n> 1.9.0\n"},{"id":"237323","messageId":"xmqqzjkjv6gx.fsf@gitster.dls.corp.google.com","threadId":"36215","inReplyTo":"CAPig+cTWV0PWOh88u+rbMPvnn3O+OhTJATEtXXi4oLKUN25Ezw@mail.gmail.com","subject":"Re: [PATCH v5] use starts_with() instead of !memcmp()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-21T16:53:18Z","receivedAt":"2014-03-21T16:53:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Tue, Mar 18, 2014 at 9:18 PM, Quint Guvernator\n> <quintus.public@gmail.com> wrote:\n>> Another version, this time very in line with the review and commentary of\n>> Junio, Eric, and Michael.  This version boasts a revamped commit message and\n>> fewer but surer hunks changed.\n>\n> Explaining what changed in this version is indeed a courtesy to\n> reviewers. Thanks.\n\nSo, is that a \"reviewed-by: Eric\"?\n"},{"id":"237337","messageId":"CAPig+cQeVYhndNEmiKFVxfGv=p2vZWmoP_nwwc+NTPLGQfbeng@mail.gmail.com","threadId":"36215","inReplyTo":"xmqqzjkjv6gx.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v5] use starts_with() instead of !memcmp()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-21T18:05:07Z","receivedAt":"2014-03-21T18:05:07Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Mar 21, 2014 at 12:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n>\n>> On Tue, Mar 18, 2014 at 9:18 PM, Quint Guvernator\n>> <quintus.public@gmail.com> wrote:\n>>> Another version, this time very in line with the review and commentary of\n>>> Junio, Eric, and Michael.  This version boasts a revamped commit message and\n>>> fewer but surer hunks changed.\n>>\n>> Explaining what changed in this version is indeed a courtesy to\n>> reviewers. Thanks.\n>\n> So, is that a \"reviewed-by: Eric\"?\n\nNo, sorry. You and Peff were actively reviewing Quint's submissions,\nso I merely scanned them quickly without making a careful examination.\nI've been commenting upon so many GSoC submissions that it's hard to\nremember which is which, and upon reading \"Another version, this time\nvery in line with the review and commentary Junio, Eric, and Michael\",\nI had to search the list archive to figure out why my name was listed.\nHence, the suggestion from me that providing a link to the previous\nattempt is a welcome courtesy.\n"}]}