{"thread":{"id":"18610","subject":"[PATCH 2/4] quote: add \"sq_dequote_to_argv\" to put unwrapped args in an argv array","startedAt":"2009-03-29T09:44:52Z","lastAt":"2009-03-31T05:09:38Z","messageCount":3,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"109756","messageId":"20090329114452.b19a2f60.chriscool@tuxfamily.org","threadId":"18610","inReplyTo":null,"subject":"[PATCH 2/4] quote: add \"sq_dequote_to_argv\" to put unwrapped args in an argv array","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-03-29T09:44:52Z","receivedAt":"2009-03-29T09:44:52Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This new function unwraps the space separated shell quoted elements in\nits first argument and put a copy of them in the argv array passed as\nits second argument.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n quote.c |   17 +++++++++++++++++\n quote.h |    2 ++\n 2 files changed, 19 insertions(+), 0 deletions(-)\n\ndiff --git a/quote.c b/quote.c\nindex 8cf0ef4..5b12a4a 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -120,6 +120,23 @@ char *sq_dequote(char *arg)\n \treturn sq_dequote_many(arg, NULL);\n }\n \n+int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)\n+{\n+\tchar *next = arg;\n+\n+\tif (!*arg)\n+\t\treturn 0;\n+\tdo {\n+\t\tchar *dequoted = sq_dequote_many(next, &next);\n+\t\tif (!dequoted)\n+\t\t\treturn 1;\n+\t\tALLOC_GROW(*argv, *nr + 1, *alloc);\n+\t\t(*argv)[(*nr)++] = xstrdup(dequoted);\n+\t} while (next);\n+\n+\treturn 0;\n+}\n+\n /* 1 means: quote as octal\n  * 0 means: quote as octal if (quote_path_fully)\n  * -1 means: never quote\ndiff --git a/quote.h b/quote.h\nindex c2f98e7..bbd0f09 100644\n--- a/quote.h\n+++ b/quote.h\n@@ -47,6 +47,8 @@ extern char *sq_dequote(char *);\n  */\n extern char *sq_dequote_many(char *arg, char **next);\n \n+extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc);\n+\n extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);\n extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);\n extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);\n-- \n1.6.2.1.404.gb0085.dirty\n"},{"id":"109838","messageId":"7vhc1bjyl7.fsf@gitster.siamese.dyndns.org","threadId":"18610","inReplyTo":"20090329114452.b19a2f60.chriscool@tuxfamily.org","subject":"Re: [PATCH 2/4] quote: add \"sq_dequote_to_argv\" to put unwrapped args in an argv array","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-30T06:48:04Z","receivedAt":"2009-03-30T06:48:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> This new function unwraps the space separated shell quoted elements in\n> its first argument and put a copy of them in the argv array passed as\n> its second argument.\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  quote.c |   17 +++++++++++++++++\n>  quote.h |    2 ++\n>  2 files changed, 19 insertions(+), 0 deletions(-)\n>\n> diff --git a/quote.c b/quote.c\n> index 8cf0ef4..5b12a4a 100644\n> --- a/quote.c\n> +++ b/quote.c\n> @@ -120,6 +120,23 @@ char *sq_dequote(char *arg)\n>  \treturn sq_dequote_many(arg, NULL);\n>  }\n>  \n> +int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)\n> +{\n> +\tchar *next = arg;\n> +\n> +\tif (!*arg)\n> +\t\treturn 0;\n> +\tdo {\n> +\t\tchar *dequoted = sq_dequote_many(next, &next);\n> +\t\tif (!dequoted)\n> +\t\t\treturn 1;\n\nUsually we signal an error with a negative value, e.g. -1.\n\n> +\t\tALLOC_GROW(*argv, *nr + 1, *alloc);\n> +\t\t(*argv)[(*nr)++] = xstrdup(dequoted);\n\nThe original sq_dequote() interface takes advantage of the fact that the\nresult of single-quote unquoting is always shorter than the original and\nit can rewrite the argument in-place to return the result.  I would expect\ndequote_step() to retain that trait and allow the caller to use its return\nvalue without xstrdup().\n\nBut please do not send in replacements just yet.\n"},{"id":"109961","messageId":"200903310709.39034.chriscool@tuxfamily.org","threadId":"18610","inReplyTo":"7vhc1bjyl7.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/4] quote: add \"sq_dequote_to_argv\" to put unwrapped args in an argv array","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-03-31T05:09:38Z","receivedAt":"2009-03-31T05:09:38Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le lundi 30 mars 2009, Junio C Hamano a écrit :\n> Christian Couder <chriscool@tuxfamily.org> writes:\n> > This new function unwraps the space separated shell quoted elements in\n> > its first argument and put a copy of them in the argv array passed as\n> > its second argument.\n> >\n> > Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> > ---\n> >  quote.c |   17 +++++++++++++++++\n> >  quote.h |    2 ++\n> >  2 files changed, 19 insertions(+), 0 deletions(-)\n> >\n> > diff --git a/quote.c b/quote.c\n> > index 8cf0ef4..5b12a4a 100644\n> > --- a/quote.c\n> > +++ b/quote.c\n> > @@ -120,6 +120,23 @@ char *sq_dequote(char *arg)\n> >  \treturn sq_dequote_many(arg, NULL);\n> >  }\n> >\n> > +int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int\n> > *alloc) +{\n> > +\tchar *next = arg;\n> > +\n> > +\tif (!*arg)\n> > +\t\treturn 0;\n> > +\tdo {\n> > +\t\tchar *dequoted = sq_dequote_many(next, &next);\n> > +\t\tif (!dequoted)\n> > +\t\t\treturn 1;\n>\n> Usually we signal an error with a negative value, e.g. -1.\n>\n> > +\t\tALLOC_GROW(*argv, *nr + 1, *alloc);\n> > +\t\t(*argv)[(*nr)++] = xstrdup(dequoted);\n>\n> The original sq_dequote() interface takes advantage of the fact that the\n> result of single-quote unquoting is always shorter than the original and\n> it can rewrite the argument in-place to return the result.  I would\n> expect dequote_step() to retain that trait and allow the caller to use\n> its return value without xstrdup().\n\nI thought that it could be dangerous not to use xstrdup, as users of this \nfunction might want to free the strings in argv one by one. But I don't \ncare much.\n\nThanks,\nChristian.\n"}]}