]> git.proxmox.com Git - mirror_qemu.git/blob - scripts/git-submodule.sh
net/vhost-net: do not assert on null pointer return from tap_get_vhost_net()
[mirror_qemu.git] / scripts / git-submodule.sh
1 #!/bin/sh
2 #
3 # This code is licensed under the GPL version 2 or later. See
4 # the COPYING file in the top-level directory.
5
6 substat=".git-submodule-status"
7
8 command=$1
9 shift
10 maybe_modules="$@"
11
12 # if not running in a git checkout, do nothing
13 test "$command" = "ignore" && exit 0
14
15 test -z "$GIT" && GIT=$(command -v git)
16
17 cd "$(dirname "$0")/.."
18
19 update_error() {
20 echo "$0: $*"
21 echo
22 echo "Unable to automatically checkout GIT submodules '$modules'."
23 echo "If you require use of an alternative GIT binary (for example to"
24 echo "enable use of a transparent proxy), please disable automatic"
25 echo "GIT submodule checkout with:"
26 echo
27 echo " $ ./configure --disable-download"
28 echo
29 echo "and then manually update submodules prior to running make, with:"
30 echo
31 echo " $ GIT='tsocks git' scripts/git-submodule.sh update $modules"
32 echo
33 exit 1
34 }
35
36 validate_error() {
37 if test "$1" = "validate"; then
38 echo "GIT submodules checkout is out of date, and submodules"
39 echo "configured for validate only. Please run"
40 echo " scripts/git-submodule.sh update $maybe_modules"
41 echo "from the source directory or call configure with"
42 echo " --enable-download"
43 fi
44 exit 1
45 }
46
47 check_updated() {
48 local CURSTATUS OLDSTATUS
49 CURSTATUS=$($GIT submodule status $module)
50 OLDSTATUS=$(grep $module $substat)
51 test "$CURSTATUS" = "$OLDSTATUS"
52 }
53
54 if test -n "$maybe_modules" && ! test -e ".git"
55 then
56 echo "$0: unexpectedly called with submodules but no git checkout exists"
57 exit 1
58 fi
59
60 if test -n "$maybe_modules" && test -z "$GIT"
61 then
62 echo "$0: unexpectedly called with submodules but git binary not found"
63 exit 1
64 fi
65
66 modules=""
67 for m in $maybe_modules
68 do
69 $GIT submodule status $m 1> /dev/null 2>&1
70 if test $? = 0
71 then
72 modules="$modules $m"
73 else
74 echo "warn: ignoring non-existent submodule $m"
75 fi
76 done
77
78 case "$command" in
79 status|validate)
80 test -f "$substat" || validate_error "$command"
81 test -z "$maybe_modules" && exit 0
82 for module in $modules; do
83 check_updated $module || validate_error "$command"
84 done
85 exit 0
86 ;;
87 update)
88 test -e $substat || touch $substat
89 test -z "$maybe_modules" && exit 0
90
91 $GIT submodule update --init $modules 1>/dev/null
92 test $? -ne 0 && update_error "failed to update modules"
93 for module in $modules; do
94 check_updated $module || echo Updated "$module"
95 done
96
97 (while read -r; do
98 for module in $modules; do
99 case $REPLY in
100 *" $module "*) continue 2 ;;
101 esac
102 done
103 printf '%s\n' "$REPLY"
104 done
105 $GIT submodule status $modules
106 test $? -ne 0 && update_error "failed to save git submodule status" >&2) < $substat > $substat.new
107 mv -f $substat.new $substat
108 ;;
109 esac
110
111 exit 0