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