On Thu, Jan 19, 2023 at 07:59:42AM +0100, Markus Armbruster wrote:
> When running with --check-dup-head, the script always claims it "Found
> duplicate header file includes."  Fix to do it only when it actually
> found some.
> 
> Fixes: d66253e46ae2b9c36a9dd90b2b74c0dfa5804b22
> Signed-off-by: Markus Armbruster <arm...@redhat.com>
> ---
>  scripts/clean-includes | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/clean-includes b/scripts/clean-includes
> index 86944f27fc..8e8420d785 100755
> --- a/scripts/clean-includes
> +++ b/scripts/clean-includes
> @@ -177,9 +177,8 @@ for f in "$@"; do
>  done
>  
>  if [ "$DUPHEAD" = "yes" ] && [ -n "$files" ]; then
> -    egrep "^[[:space:]]*#[[:space:]]*include" $files | tr -d '[:blank:]' \
> -        | sort | uniq -c | awk '{if ($1 > 1) print $0}'
> -    if [ $? -eq 0 ]; then
> +    if egrep "^[[:space:]]*#[[:space:]]*include" $files | tr -d '[:blank:]' \
> +        | sort | uniq -c | grep -v '^ *1 '; then

Indeed - the awk script was succeeding even if it printed nothing,
whereas the grep -v is a bit lighter-weight and has the intended
semantics of exit status based on output.

Reviewed-by: Eric Blake <ebl...@redhat.com>

>          echo "Found duplicate header file includes. Please check the above 
> files manually."
>          exit 1
>      fi
> -- 
> 2.39.0
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


Reply via email to