{"thread":{"id":"52344","subject":"[PATCH] shell: use skip_prefix() instead of starts_with()","startedAt":"2019-11-26T15:00:50Z","lastAt":"2019-11-26T16:41:17Z","messageCount":3,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"387083","messageId":"0a4dfbcc-9eb5-6b39-6b93-0014f5c475de@web.de","threadId":"52344","inReplyTo":null,"subject":"[PATCH] shell: use skip_prefix() instead of starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-26T15:00:43Z","receivedAt":"2019-11-26T15:00:50Z","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() instead of\nstarts_with().\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n shell.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/shell.c b/shell.c\nindex 40084a3013..54cca7439d 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)\n \tsetup_path();\n \tif (!arg || !(arg = sq_dequote(arg)) || *arg == '-')\n \t\tdie(\"bad argument\");\n-\tif (!starts_with(me, \"git-\"))\n+\tif (!skip_prefix(me, \"git-\", &me))\n \t\tdie(\"bad command\");\n\n-\tmy_argv[0] = me + 4;\n+\tmy_argv[0] = me;\n \tmy_argv[1] = arg;\n \tmy_argv[2] = NULL;\n\n--\n2.24.0\n"},{"id":"387088","messageId":"20191126155647.GA25729@sigill.intra.peff.net","threadId":"52344","inReplyTo":"0a4dfbcc-9eb5-6b39-6b93-0014f5c475de@web.de","subject":"Re: [PATCH] shell: use skip_prefix() instead of starts_with()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-26T15:56:47Z","receivedAt":"2019-11-26T15:56:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 26, 2019 at 04:00:43PM +0100, René Scharfe wrote:\n\n> Get rid of a magic number by using skip_prefix() instead of\n> starts_with().\n> \n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  shell.c | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/shell.c b/shell.c\n> index 40084a3013..54cca7439d 100644\n> --- a/shell.c\n> +++ b/shell.c\n> @@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)\n>  \tsetup_path();\n>  \tif (!arg || !(arg = sq_dequote(arg)) || *arg == '-')\n>  \t\tdie(\"bad argument\");\n> -\tif (!starts_with(me, \"git-\"))\n> +\tif (!skip_prefix(me, \"git-\", &me))\n>  \t\tdie(\"bad command\");\n> \n> -\tmy_argv[0] = me + 4;\n> +\tmy_argv[0] = me;\n>  \tmy_argv[1] = arg;\n>  \tmy_argv[2] = NULL;\n\nThe context makes this look obviously correct, but one thing to watch\nout for in these skip_prefix() conversions is that the value of \"me\" is\nnow mutated.  This one is fine, because nobody else looks at \"me\" after\nthis (knowing you, I am pretty sure you checked that already, but I am\nmaking a mental note to myself and others as we review these).\n\n-Peff\n"},{"id":"387093","messageId":"baf0aabe-f94e-852a-7c60-0c6e772fc437@web.de","threadId":"52344","inReplyTo":"20191126155647.GA25729@sigill.intra.peff.net","subject":"Re: [PATCH] shell: use skip_prefix() instead of starts_with()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-26T16:41:09Z","receivedAt":"2019-11-26T16:41:17Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 26.11.19 um 16:56 schrieb Jeff King:\n> On Tue, Nov 26, 2019 at 04:00:43PM +0100, René Scharfe wrote:\n>\n>> Get rid of a magic number by using skip_prefix() instead of\n>> starts_with().\n>>\n>> Signed-off-by: René Scharfe <l.s.r@web.de>\n>> ---\n>>  shell.c | 4 ++--\n>>  1 file changed, 2 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/shell.c b/shell.c\n>> index 40084a3013..54cca7439d 100644\n>> --- a/shell.c\n>> +++ b/shell.c\n>> @@ -16,10 +16,10 @@ static int do_generic_cmd(const char *me, char *arg)\n>>  \tsetup_path();\n>>  \tif (!arg || !(arg = sq_dequote(arg)) || *arg == '-')\n>>  \t\tdie(\"bad argument\");\n>> -\tif (!starts_with(me, \"git-\"))\n>> +\tif (!skip_prefix(me, \"git-\", &me))\n>>  \t\tdie(\"bad command\");\n>>\n>> -\tmy_argv[0] = me + 4;\n>> +\tmy_argv[0] = me;\n>>  \tmy_argv[1] = arg;\n>>  \tmy_argv[2] = NULL;\n>\n> The context makes this look obviously correct, but one thing to watch\n> out for in these skip_prefix() conversions is that the value of \"me\" is\n> now mutated.\n\nAh, the one time I didn't use --function-context..  It would have looked\nlike this:\n\n---\n shell.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/shell.c b/shell.c\nindex 40084a3013..54cca7439d 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -12,16 +12,16 @@\n static int do_generic_cmd(const char *me, char *arg)\n {\n \tconst char *my_argv[4];\n\n \tsetup_path();\n \tif (!arg || !(arg = sq_dequote(arg)) || *arg == '-')\n \t\tdie(\"bad argument\");\n-\tif (!starts_with(me, \"git-\"))\n+\tif (!skip_prefix(me, \"git-\", &me))\n \t\tdie(\"bad command\");\n\n-\tmy_argv[0] = me + 4;\n+\tmy_argv[0] = me;\n \tmy_argv[1] = arg;\n \tmy_argv[2] = NULL;\n\n \treturn execv_git_cmd(my_argv);\n }\n--\n2.24.0\n\n\n\n"}]}