diff mbox series

[PULL,14/21] git-submodule: allow partial update of .git-submodule-status

Message ID 20230606143116.685644-15-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series [PULL,01/21] meson: Avoid implicit declaration of absent functions | expand

Commit Message

Paolo Bonzini June 6, 2023, 2:31 p.m. UTC
Allow a specific subdirectory to run git-submodule.sh with only a
subset of submodules, without removing the others from the
.git-submodule-status file.

This also allows scripts/git-submodule.sh to be more lenient:
validating an empty set of submodules is not a mistake.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/git-submodule.sh | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Peter Maydell July 20, 2023, 3:08 p.m. UTC | #1
On Tue, 6 Jun 2023 at 15:34, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Allow a specific subdirectory to run git-submodule.sh with only a
> subset of submodules, without removing the others from the
> .git-submodule-status file.
>
> This also allows scripts/git-submodule.sh to be more lenient:
> validating an empty set of submodules is not a mistake.
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

I've noticed that when doing a build sometimes this
script now produces an error:

make: Entering directory
'/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/clang'
/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/pc-bios/s390-ccw/../../scripts/git-submodule.sh:
106: read: arg count
[1/154] Generating qemu-version.h with a custom command (wrapped by
meson to capture output)
[etc]


> -    $GIT submodule status $modules > "${substat}"
> -    test $? -ne 0 && update_error "failed to save git submodule status" >&2
> +    (while read -r; do

This is because "read" without a variable name argument is
a non-POSIX extension. I think the fix to this is to say
"read -r REPLY" rather than omitting the variable name and
assuming it will default to REPLY.

> +        for module in $modules; do
> +            case $REPLY in
> +                *" $module "*) continue 2 ;;
> +            esac
> +        done
> +        printf '%s\n' "$REPLY"
> +    done

I'll send a patch shortly.

thanks
-- PMM
diff mbox series

Patch

diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh
index 0ce1efc44e5..b7d8f05352c 100755
--- a/scripts/git-submodule.sh
+++ b/scripts/git-submodule.sh
@@ -72,12 +72,8 @@  done
 
 case "$command" in
 status|validate)
-    if test -z "$maybe_modules"
-    then
-         test -s ${substat} && validate_error "$command" || exit 0
-    fi
-
     test -f "$substat" || validate_error "$command"
+    test -z "$maybe_modules" && exit 0
     for module in $modules; do
         CURSTATUS=$($GIT submodule status $module)
         OLDSTATUS=$(cat $substat | grep $module)
@@ -88,17 +84,23 @@  status|validate)
     exit 0
     ;;
 update)
-    if test -z "$maybe_modules"
-    then
-        test -e $substat || touch $substat
-        exit 0
-    fi
+    test -e $substat || touch $substat
+    test -z "$maybe_modules" && exit 0
 
     $GIT submodule update --init $modules 1>/dev/null
     test $? -ne 0 && update_error "failed to update modules"
 
-    $GIT submodule status $modules > "${substat}"
-    test $? -ne 0 && update_error "failed to save git submodule status" >&2
+    (while read -r; do
+        for module in $modules; do
+            case $REPLY in
+                *" $module "*) continue 2 ;;
+            esac
+        done
+        printf '%s\n' "$REPLY"
+    done
+    $GIT submodule status $modules
+    test $? -ne 0 && update_error "failed to save git submodule status" >&2) < $substat > $substat.new
+    mv -f $substat.new $substat
     ;;
 esac