{"thread":{"id":"52341","subject":"[PATCH] fetch: use skip_prefix() instead of starts_with()","startedAt":"2019-11-26T11:18:36Z","lastAt":"2019-11-26T16:09:37Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"387078","messageId":"f6ed729b-3cd3-a91a-d69d-4960e4a0524f@web.de","threadId":"52341","inReplyTo":null,"subject":"[PATCH] fetch: use skip_prefix() instead of starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-26T11:18:26Z","receivedAt":"2019-11-26T11:18:36Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Get rid of magic numbers by letting skip_prefix() set the pointer\n\"what\".\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/fetch.c | 12 +++---------\n 1 file changed, 3 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 863c858fde..02e8619618 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -954,18 +954,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\t\tkind = \"\";\n \t\t\t\twhat = \"\";\n \t\t\t}\n-\t\t\telse if (starts_with(rm->name, \"refs/heads/\")) {\n+\t\t\telse if (skip_prefix(rm->name, \"refs/heads/\", &what))\n \t\t\t\tkind = \"branch\";\n-\t\t\t\twhat = rm->name + 11;\n-\t\t\t}\n-\t\t\telse if (starts_with(rm->name, \"refs/tags/\")) {\n+\t\t\telse if (skip_prefix(rm->name, \"refs/tags/\", &what))\n \t\t\t\tkind = \"tag\";\n-\t\t\t\twhat = rm->name + 10;\n-\t\t\t}\n-\t\t\telse if (starts_with(rm->name, \"refs/remotes/\")) {\n+\t\t\telse if (skip_prefix(rm->name, \"refs/remotes/\", &what))\n \t\t\t\tkind = \"remote-tracking branch\";\n-\t\t\t\twhat = rm->name + 13;\n-\t\t\t}\n \t\t\telse {\n \t\t\t\tkind = \"\";\n \t\t\t\twhat = rm->name;\n--\n2.24.0\n"},{"id":"387091","messageId":"20191126160934.GD25729@sigill.intra.peff.net","threadId":"52341","inReplyTo":"f6ed729b-3cd3-a91a-d69d-4960e4a0524f@web.de","subject":"Re: [PATCH] fetch: use skip_prefix() instead of starts_with()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-26T16:09:34Z","receivedAt":"2019-11-26T16:09:37Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 26, 2019 at 12:18:26PM +0100, René Scharfe wrote:\n\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 863c858fde..02e8619618 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -954,18 +954,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n>  \t\t\t\tkind = \"\";\n>  \t\t\t\twhat = \"\";\n>  \t\t\t}\n> -\t\t\telse if (starts_with(rm->name, \"refs/heads/\")) {\n> +\t\t\telse if (skip_prefix(rm->name, \"refs/heads/\", &what))\n>  \t\t\t\tkind = \"branch\";\n> -\t\t\t\twhat = rm->name + 11;\n> -\t\t\t}\n> -\t\t\telse if (starts_with(rm->name, \"refs/tags/\")) {\n> +\t\t\telse if (skip_prefix(rm->name, \"refs/tags/\", &what))\n>  \t\t\t\tkind = \"tag\";\n> -\t\t\t\twhat = rm->name + 10;\n> -\t\t\t}\n> -\t\t\telse if (starts_with(rm->name, \"refs/remotes/\")) {\n> +\t\t\telse if (skip_prefix(rm->name, \"refs/remotes/\", &what))\n>  \t\t\t\tkind = \"remote-tracking branch\";\n> -\t\t\t\twhat = rm->name + 13;\n> -\t\t\t}\n>  \t\t\telse {\n\nYep, this one looks obviously correct. We were already mutating \"what\",\nso this just does it inside skip_prefix(). Much nicer.\n\n-Peff\n"}]}