What's cooking (2021/06 #06)
[git] / Dothem
1 #!/bin/sh
2
3 NWD=contrib/workdir/git-new-workdir
4 MASTER=master
5
6 inst_prefix=$(
7         IFS=:
8         for p in $PATH
9         do
10                 probed=${p%/git-active/bin}
11                 if test "$probed" != "$p"
12                 then
13                         echo "$probed"
14                         exit
15                 fi
16         done
17         echo $HOME
18 )
19
20 force= with_dash= test_long= M= install= nodoc= notest= bootstrap= branches= jobs=
21 scratch= noprove= memtrash=--memtrash with_cocci=
22 while   case "$1" in
23         --pedantic | --locale=* | --loose) M="$M $1" ;;
24         --force) force=$1 ;;
25         --dash) with_dash=y ;;
26         --cocci) with_cocci=y ;;
27         --no-cocci) with_cocci= ;;
28         --long) test_long=--long ;;
29         --noinstall) install=noinstall ;;
30         --nodoc) nodoc=y ;;
31         --notest) notest=y ;;
32         --nomemtrash) memtrash= ;;
33         --memtrash) memtrash=--memtrash ;;
34         --test=*) test="$1" ;;
35         --scratch) scratch=y ;;
36         --bootstrap) bootstrap=y ;;
37         --base=*) BUILDBASE=${1#*=} ;;
38         --branches=*) branches=${1#*=} ;;
39         --noprove) noprove=$1 ;;
40         -j*) jobs=$1 ;;
41         --) shift; break ;;
42         -*) echo >&2 "Unknown option: $1"; exit 1 ;;
43         *) break ;;
44         esac
45 do
46         shift
47 done
48
49 sh -c 'asciidoc --version >/dev/null 2>&1' || nodoc=y
50
51 GIT_TEST_CHAIN_LINT=1
52 export GIT_TEST_CHAIN_LINT
53
54 GIT_PROVE_OPTS="${GIT_PROVE_OPTS:+$GIT_PROVE_OPTS }--state=slow,save"
55 export GIT_PROVE_OPTS
56
57 test -f /bin/dash || with_dash=
58 if test -z "$BUILDBASE"
59 then
60         if test -d "$inst_prefix/buildfarm"
61         then
62                 BUILDBASE="$inst_prefix/buildfarm"
63         elif test -d "../buildfarm"
64         then
65                 BUILDBASE=../buildfarm
66         else
67                 echo >&2 "Buildbase unknown"
68                 exit 1
69         fi
70 fi
71 test -n "$branches" || branches="next $MASTER maint jch seen"
72 test -n "$jobs" || jobs=-j2
73
74 find_installed () {
75         branch=$1
76         test -f "$inst_prefix/git-$branch/bin/git" &&
77         installed=$($inst_prefix/git-$branch/bin/git version) &&
78         if version=$(expr "$installed" : '.*\.g\([0-9a-f]*\)$')
79         then
80                 :
81         elif version=v$(expr "$installed" : \
82                 'git version \(.*\)\.rc[0-9]*$')
83         then
84                 version="$version"-$(expr "$installed" : \
85                         'git version .*\.\(rc[0-9]*\)$')
86         else
87                 version=v$(expr "$installed" : 'git version \(.*\)')
88         fi &&
89         git rev-parse --verify "$version^0" 2>/dev/null
90 }
91
92 installed_source_trees=" "
93 for branch in $branches
94 do
95         if      v=$(find_installed $branch) &&
96                 test -n "$v" &&
97                 v=$(git rev-parse --verify "$v^{tree}" 2>/dev/null)
98         then
99                 installed_source_trees="$installed_source_trees$v "
100         fi
101 done
102
103 for branch in $branches
104 do
105         echo "** $branch **"
106         revision=$(git show-ref -s --verify "refs/heads/$branch") || {
107                 echo "** No $branch"
108                 continue
109         }
110
111         if test ! -d "$BUILDBASE/$branch"
112         then
113                 if test -z "$bootstrap"
114                 then
115                         echo "** No $BUILDBASE/$branch"
116                         continue
117                 fi
118                 "$NWD" . "$BUILDBASE/$branch" $branch &&
119                 ln -s "$(pwd)/Meta" "$BUILDBASE/$branch/Meta" || {
120                         echo "** Failed to bootstrap $BUILDBASE/$branch"
121                         continue
122                 }
123         fi
124
125         private=$(git rev-parse -q --verify private-$branch 2>/dev/null)
126         case $? in 0|1) ;; *) exit $? ;; esac
127
128         version=$(find_installed $branch)
129         if      test "z$version" = "z$revision"
130         then
131                 echo "* up-to-date version is already installed from $branch"
132                 test -n "$force" || continue
133         fi
134
135         vtree=$(git rev-parse --verify "$version^{tree}")
136         rtree=$(git rev-parse --verify "$revision^{tree}")
137         (
138                 skip_test=$notest skip_doc=$nodoc
139                 case "$force" in
140                 ?*)
141                         ;;
142                 '')
143                         for xtree in $installed_source_trees $vtree
144                         do
145                                 if test "z$xtree" = "z$rtree" ||
146                                         git diff --quiet "$xtree" "$rtree" -- . \
147                                         ':!GIT-VERSION-GEN' \
148                                         ':!RelNotes' \
149                                         ':!Documentation/'
150                                 then
151                                         skip_test=1
152                                         break
153                                 fi
154                         done
155
156                         dvtree=$(git rev-parse --verify "$version:Documentation/")
157                         drtree=$(git rev-parse --verify "$revision:Documentation/")
158                         if test "z$dvtree" = "z$drtree"
159                         then
160                                 skip_doc=1
161                         fi
162                         ;;
163                 esac
164
165                 case "$skip_test" in
166                 ?*)     dotest= ;;
167                 '')     dotest=test ;;
168                 esac
169
170                 cd "$BUILDBASE/$branch"
171                 git reset --hard  &&
172
173                 case "$scratch" in
174                 '')
175                         ;;
176                 y)
177                         saveMeta=$(readlink Meta)
178                         Meta/Make distclean
179                         git clean -f -x
180                         ln -s "$saveMeta" Meta
181                         ;;
182                 esac &&
183
184                 case "$(git symbolic-ref HEAD)" in
185                 "refs/heads/$branch")
186                         : ;;
187                 *)
188                         git checkout "$branch" &&
189                         git reset --hard || exit
190                 esac &&
191
192                 case "$private" in
193                 '')
194                         ;;
195                 ?*)
196                         git merge --squash --no-commit "$private" || {
197                                 echo >&2 "** Cannot apply private edition changes"
198                                 git reset --hard
199                         }
200                         ;;
201                 esac &&
202
203                 save=$(git rev-parse HEAD) &&
204
205                 if test -n "$with_cocci"
206                 then
207                         Meta/Make $M $jobs -- coccicheck
208                 fi &&
209
210                 Meta/Make $M $jobs -- SPARSE_FLAGS=-Wsparse-error sparse &&
211
212                 Meta/Make $M $noprove ${test+"$test"} $jobs $test_long $memtrash \
213                     -- ${with_dash:+SHELL_PATH=/bin/dash} "$@" $dotest &&
214
215                 {
216                         test -n "$skip_doc" ||
217                         if test "$save" = "$(git rev-parse HEAD)"
218                         then
219                                 Meta/Make $M $jobs -- doc &&
220                                 Meta/Make $M -- install-man install-html
221                         else
222                                 echo >&2 "Head moved--not installing docs"
223                         fi
224                 } &&
225
226                 {
227                         test z$install = znoinstall ||
228                         if test "$save" = "$(git rev-parse HEAD)"
229                         then
230                                 Meta/Make $M -- ${with_dash:+SHELL_PATH=/bin/dash} "$@" install
231                         else
232                                 echo >&2 "Head moved--not installing"
233                         fi
234                 } || exit $?
235
236                 git reset --hard
237         ) </dev/null || exit $?
238
239         installed_source_trees="$installed_source_trees$rtree "
240 done