[PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages

Peter Maydell posted 6 patches 3 weeks ago
[PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Posted by Peter Maydell 3 weeks ago
If clean-includes is creating a git commit for its changes,
currently it says only "created with scripts/clean-includes".
Add the command line arguments the user passed us, as useful
extra information.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 scripts/clean-includes | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/scripts/clean-includes b/scripts/clean-includes
index a45421d2ff..b16eec0a5c 100755
--- a/scripts/clean-includes
+++ b/scripts/clean-includes
@@ -42,6 +42,28 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message, quoted for the shell so that we handle
+# args with spaces/metacharacters correctly.
+# The quote_sh() function is the same one we use in configure.
+
+quote_sh() {
+    for arg in "$@"; do
+        printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&',"
+    done
+}
+
+quote_args() {
+    while [ $# -gt 0 ]; do
+        printf "%s" "$(quote_sh "$1")"
+        shift
+        if [ $# -gt 0 ]; then
+            printf " "
+        fi
+    done
+}
+
+QUOTEDARGS="$(quote_args "$@")"
 
 while true
 do
@@ -198,7 +220,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $QUOTEDARGS
 
 All .c should include qemu/osdep.h first.  The script performs three
 related cleanups:
-- 
2.47.3
Re: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Posted by Markus Armbruster 3 weeks ago
Peter Maydell <peter.maydell@linaro.org> writes:

> If clean-includes is creating a git commit for its changes,
> currently it says only "created with scripts/clean-includes".
> Add the command line arguments the user passed us, as useful
> extra information.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  scripts/clean-includes | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/clean-includes b/scripts/clean-includes
> index a45421d2ff..b16eec0a5c 100755
> --- a/scripts/clean-includes
> +++ b/scripts/clean-includes
> @@ -42,6 +42,28 @@
>  GIT=no
>  DUPHEAD=no
>  
> +# Save the original arguments in case we want to put them in
> +# a git commit message, quoted for the shell so that we handle
> +# args with spaces/metacharacters correctly.
> +# The quote_sh() function is the same one we use in configure.

Not quite, configure's is

   quote_sh() {
       printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
   }

> +
> +quote_sh() {
> +    for arg in "$@"; do
> +        printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&',"
> +    done
> +}

Is the loop intentional?  We seem to always call the function with
exactly one argument.

> +
> +quote_args() {
> +    while [ $# -gt 0 ]; do
> +        printf "%s" "$(quote_sh "$1")"
> +        shift
> +        if [ $# -gt 0 ]; then
> +            printf " "
> +        fi
> +    done
> +}
> +
> +QUOTEDARGS="$(quote_args "$@")"
>  
>  while true
>  do
> @@ -198,7 +220,8 @@ if [ "$GIT" = "yes" ]; then
>      git commit --signoff -F - <<EOF
>  $GITSUBJ: Clean up includes
>  
> -This commit was created with scripts/clean-includes.
> +This commit was created with scripts/clean-includes:
> + ./scripts/clean-includes $QUOTEDARGS
>  
>  All .c should include qemu/osdep.h first.  The script performs three
>  related cleanups:
Re: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Posted by Peter Maydell 3 weeks ago
On Fri, 16 Jan 2026 at 13:28, Markus Armbruster <armbru@redhat.com> wrote:
>
> Peter Maydell <peter.maydell@linaro.org> writes:
>
> > If clean-includes is creating a git commit for its changes,
> > currently it says only "created with scripts/clean-includes".
> > Add the command line arguments the user passed us, as useful
> > extra information.
> >
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
> >  scripts/clean-includes | 25 ++++++++++++++++++++++++-
> >  1 file changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/scripts/clean-includes b/scripts/clean-includes
> > index a45421d2ff..b16eec0a5c 100755
> > --- a/scripts/clean-includes
> > +++ b/scripts/clean-includes
> > @@ -42,6 +42,28 @@
> >  GIT=no
> >  DUPHEAD=no
> >
> > +# Save the original arguments in case we want to put them in
> > +# a git commit message, quoted for the shell so that we handle
> > +# args with spaces/metacharacters correctly.
> > +# The quote_sh() function is the same one we use in configure.
>
> Not quite, configure's is
>
>    quote_sh() {
>        printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
>    }
>
> > +
> > +quote_sh() {
> > +    for arg in "$@"; do
> > +        printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&',"
> > +    done
> > +}
>
> Is the loop intentional?  We seem to always call the function with
> exactly one argument.

Whoops, no -- I was iterating around trying to get something
working and didn't notice that I'd left that loop in place.
The quote_sh() function should match the configure one.

-- PMM
Re: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Posted by Markus Armbruster 3 weeks ago
Peter Maydell <peter.maydell@linaro.org> writes:

> On Fri, 16 Jan 2026 at 13:28, Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>> > If clean-includes is creating a git commit for its changes,
>> > currently it says only "created with scripts/clean-includes".
>> > Add the command line arguments the user passed us, as useful
>> > extra information.
>> >
>> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> > ---
>> >  scripts/clean-includes | 25 ++++++++++++++++++++++++-
>> >  1 file changed, 24 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/scripts/clean-includes b/scripts/clean-includes
>> > index a45421d2ff..b16eec0a5c 100755
>> > --- a/scripts/clean-includes
>> > +++ b/scripts/clean-includes
>> > @@ -42,6 +42,28 @@
>> >  GIT=no
>> >  DUPHEAD=no
>> >
>> > +# Save the original arguments in case we want to put them in
>> > +# a git commit message, quoted for the shell so that we handle
>> > +# args with spaces/metacharacters correctly.
>> > +# The quote_sh() function is the same one we use in configure.
>>
>> Not quite, configure's is
>>
>>    quote_sh() {
>>        printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
>>    }
>>
>> > +
>> > +quote_sh() {
>> > +    for arg in "$@"; do
>> > +        printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&',"
>> > +    done
>> > +}
>>
>> Is the loop intentional?  We seem to always call the function with
>> exactly one argument.
>
> Whoops, no -- I was iterating around trying to get something
> working and didn't notice that I'd left that loop in place.
> The quote_sh() function should match the configure one.

Got it.

With that
Reviewed-by: Markus Armbruster <armbru@redhat.com>