{"thread":{"id":"52345","subject":"[PATCH] push: use skip_prefix() instead of starts_with()","startedAt":"2019-11-26T15:18:34Z","lastAt":"2019-11-26T15:57:44Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"387084","messageId":"90f94e4b-6cf3-58cc-01dc-c3d731037217@web.de","threadId":"52345","inReplyTo":null,"subject":"[PATCH] push: use skip_prefix() instead of starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-26T15:18:28Z","receivedAt":"2019-11-26T15:18:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Get rid of a magic number by using skip_prefix().\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/push.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 843f5b22a2..6dbf0f0bb7 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;\n static const char *map_refspec(const char *ref,\n \t\t\t       struct remote *remote, struct ref *local_refs)\n {\n+\tconst char *branch_name;\n \tstruct ref *matched = NULL;\n\n \t/* Does \"ref\" uniquely name our ref? */\n@@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,\n \t}\n\n \tif (push_default == PUSH_DEFAULT_UPSTREAM &&\n-\t    starts_with(matched->name, \"refs/heads/\")) {\n-\t\tstruct branch *branch = branch_get(matched->name + 11);\n+\t    skip_prefix(matched->name, \"refs/heads/\", &branch_name)) {\n+\t\tstruct branch *branch = branch_get(branch_name);\n \t\tif (branch->merge_nr == 1 && branch->merge[0]->src) {\n \t\t\tstruct strbuf buf = STRBUF_INIT;\n \t\t\tstrbuf_addf(&buf, \"%s:%s\",\n--\n2.24.0\n"},{"id":"387089","messageId":"20191126155741.GB25729@sigill.intra.peff.net","threadId":"52345","inReplyTo":"90f94e4b-6cf3-58cc-01dc-c3d731037217@web.de","subject":"Re: [PATCH] push: use skip_prefix() instead of starts_with()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-26T15:57:41Z","receivedAt":"2019-11-26T15:57:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 26, 2019 at 04:18:28PM +0100, René Scharfe wrote:\n\n> diff --git a/builtin/push.c b/builtin/push.c\n> index 843f5b22a2..6dbf0f0bb7 100644\n> --- a/builtin/push.c\n> +++ b/builtin/push.c\n> @@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;\n>  static const char *map_refspec(const char *ref,\n>  \t\t\t       struct remote *remote, struct ref *local_refs)\n>  {\n> +\tconst char *branch_name;\n>  \tstruct ref *matched = NULL;\n> \n>  \t/* Does \"ref\" uniquely name our ref? */\n> @@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,\n>  \t}\n> \n>  \tif (push_default == PUSH_DEFAULT_UPSTREAM &&\n> -\t    starts_with(matched->name, \"refs/heads/\")) {\n> -\t\tstruct branch *branch = branch_get(matched->name + 11);\n> +\t    skip_prefix(matched->name, \"refs/heads/\", &branch_name)) {\n> +\t\tstruct branch *branch = branch_get(branch_name);\n\nYep, obviously correct because you introduce a new variable instead of\nmutating an existing one. Looks good.\n\n-Peff\n"}]}