]>
Commit | Line | Data |
---|---|---|
e440a328 | 1 | #!/bin/sh |
2 | ||
3 | # Copyright 2009 The Go Authors. All rights reserved. | |
4 | # Use of this source code is governed by a BSD-style | |
5 | # license that can be found in the LICENSE file. | |
6 | ||
7 | # This script merges changes from the master copy of the Go library | |
8 | # into the libgo library. This does the easy stuff; the hard stuff is | |
9 | # left to the user. | |
10 | ||
4a3da3a8 | 11 | # The file MERGE should hold the Git revision number of the last |
e440a328 | 12 | # revision which was merged into these sources. Given that, and given |
13 | # the current sources, we can run the usual diff3 algorithm to merge | |
14 | # all changes into our sources. | |
15 | ||
16 | set -e | |
17 | ||
18 | TMPDIR=${TMPDIR:-/tmp} | |
19 | ||
20 | OLDDIR=${TMPDIR}/libgo-merge-old | |
21 | NEWDIR=${TMPDIR}/libgo-merge-new | |
22 | ||
23 | if ! test -f MERGE; then | |
24 | echo 1>&2 "merge.sh: must be run in libgo source directory" | |
25 | exit 1 | |
26 | fi | |
27 | ||
b2c1d8d7 | 28 | rev=weekly |
29 | case $# in | |
30 | 1) ;; | |
31 | 2) rev=$2 ;; | |
32 | *) | |
4a3da3a8 | 33 | echo 1>&2 "merge.sh: Usage: merge.sh git-repository [revision]" |
e440a328 | 34 | exit 1 |
b2c1d8d7 | 35 | ;; |
36 | esac | |
e440a328 | 37 | |
38 | repository=$1 | |
39 | ||
49b4e44b | 40 | old_rev=`sed 1q MERGE` |
e440a328 | 41 | |
42 | rm -rf ${OLDDIR} | |
d145bc23 | 43 | git clone ${repository} ${OLDDIR} |
44 | (cd ${OLDDIR} && git checkout ${old_rev}) | |
e440a328 | 45 | |
46 | rm -rf ${NEWDIR} | |
d145bc23 | 47 | git clone ${repository} ${NEWDIR} |
48 | (cd ${NEWDIR} && git checkout ${rev}) | |
e440a328 | 49 | |
d145bc23 | 50 | new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'` |
e440a328 | 51 | |
52 | merge() { | |
53 | name=$1 | |
54 | old=$2 | |
55 | new=$3 | |
56 | libgo=$4 | |
57 | if ! test -f ${new}; then | |
58 | # The file does not exist in the new version. | |
59 | if ! test -f ${old}; then | |
60 | echo 1>&2 "merge.sh internal error no files $old $new" | |
61 | exit 1 | |
62 | fi | |
63 | if ! test -f ${libgo}; then | |
64 | # File removed in new version and libgo. | |
65 | :; | |
66 | else | |
67 | echo "merge.sh: ${name}: REMOVED" | |
68 | rm -f ${libgo} | |
4a3da3a8 | 69 | git rm ${libgo} |
e440a328 | 70 | fi |
71 | elif test -f ${old}; then | |
72 | # The file exists in the old version. | |
73 | if ! test -f ${libgo}; then | |
b6a78a82 | 74 | if ! cmp -s ${old} ${new}; then |
75 | echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo" | |
76 | fi | |
33d1d391 | 77 | return |
e440a328 | 78 | fi |
79 | if cmp -s ${old} ${libgo}; then | |
80 | # The libgo file is unchanged from the old version. | |
81 | if cmp -s ${new} ${libgo}; then | |
82 | # File is unchanged from old to new version. | |
33d1d391 | 83 | return |
e440a328 | 84 | fi |
85 | # Update file in libgo. | |
86 | echo "merge.sh: $name: updating" | |
87 | cp ${new} ${libgo} | |
88 | else | |
89 | # The libgo file has local changes. | |
90 | set +e | |
91 | diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp | |
92 | status=$? | |
93 | set -e | |
94 | case $status in | |
95 | 0) | |
96 | echo "merge.sh: $name: updating" | |
97 | mv ${libgo}.tmp ${libgo} | |
98 | ;; | |
99 | 1) | |
100 | echo "merge.sh: $name: CONFLICTS" | |
101 | mv ${libgo}.tmp ${libgo} | |
e440a328 | 102 | ;; |
103 | *) | |
ccea2b36 | 104 | echo 1>&2 "merge.sh: $name: DIFF3 FAILURE" |
e440a328 | 105 | ;; |
106 | esac | |
107 | fi | |
108 | else | |
109 | # The file does not exist in the old version. | |
110 | if test -f ${libgo}; then | |
111 | if ! cmp -s ${new} ${libgo}; then | |
112 | echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD" | |
113 | fi | |
114 | else | |
115 | echo "merge.sh: $name: NEW" | |
116 | dir=`dirname ${libgo}` | |
117 | if ! test -d ${dir}; then | |
118 | mkdir -p ${dir} | |
119 | fi | |
120 | cp ${new} ${libgo} | |
4a3da3a8 | 121 | git add ${libgo} |
e440a328 | 122 | fi |
123 | fi | |
124 | } | |
125 | ||
be239ed2 | 126 | echo ${rev} > VERSION |
c5025ca0 | 127 | |
f11c2155 | 128 | (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do |
ccea2b36 | 129 | skip=false |
130 | case "$f" in | |
31975c5e | 131 | ./cmd/buildid/* | ./cmd/cgo/* | ./cmd/go/* | ./cmd/gofmt/* | ./cmd/testjson/* | ./cmd/vet/* | ./cmd/internal/browser/* | ./cmd/internal/buildid/* | ./cmd/internal/edit/* | ./cmd/internal/objabi/* | ./cmd/internal/testj2on/* | ./cmd/internal/sys/* | ./cmd/vendor/golang.org/x/tools/* ) |
ccea2b36 | 132 | ;; |
133 | ./cmd/*) | |
134 | skip=true | |
135 | ;; | |
136 | ./runtime/race/*) | |
137 | skip=true | |
138 | ;; | |
139 | esac | |
140 | if test "$skip" = "true"; then | |
141 | continue | |
142 | fi | |
143 | ||
f11c2155 | 144 | oldfile=${OLDDIR}/src/$f |
145 | newfile=${NEWDIR}/src/$f | |
31975c5e | 146 | libgofile=go/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'` |
e440a328 | 147 | merge $f ${oldfile} ${newfile} ${libgofile} |
148 | done | |
149 | ||
f11c2155 | 150 | (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do |
ccea2b36 | 151 | skip=false |
364cd319 | 152 | case "$d" in |
31975c5e | 153 | ./cmd/buildid/* | ./cmd/cgo/* | ./cmd/go/* | ./cmd/gofmt/* | ./cmd/testjson/* | ./cmd/vet/* | ./cmd/internal/browser/* | ./cmd/internal/buildid/* | ./cmd/internal/edit/* | ./cmd/internal/objabi/* | ./cmd/internal/testj2on/* | ./cmd/internal/sys/* | ./cmd/vendor/golang.org/x/tools/* ) |
ccea2b36 | 154 | ;; |
155 | ./cmd/*) | |
156 | skip=true | |
157 | ;; | |
33d1d391 | 158 | ./runtime/race/* | ./runtime/cgo/*) |
ccea2b36 | 159 | skip=true |
160 | ;; | |
161 | esac | |
162 | if test "$skip" = "true"; then | |
163 | continue | |
164 | fi | |
165 | ||
f11c2155 | 166 | oldtd=${OLDDIR}/src/$d |
167 | newtd=${NEWDIR}/src/$d | |
31975c5e | 168 | libgofile=go/`echo $d | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'` |
e440a328 | 169 | if ! test -d ${oldtd}; then |
ccea2b36 | 170 | echo "merge.sh: $d: NEWDIR" |
e440a328 | 171 | continue |
172 | fi | |
d145bc23 | 173 | (cd ${oldtd} && git ls-files .) | while read f; do |
174 | if test "`basename $f`" = ".gitignore"; then | |
e440a328 | 175 | continue |
176 | fi | |
e440a328 | 177 | name=$d/$f |
178 | oldfile=${oldtd}/$f | |
179 | newfile=${newtd}/$f | |
180 | libgofile=${libgotd}/$f | |
181 | merge ${name} ${oldfile} ${newfile} ${libgofile} | |
182 | done | |
183 | done | |
184 | ||
aaff1ad7 | 185 | (cd ${NEWDIR}/misc/cgo && find . -type f -print) | while read f; do |
186 | oldfile=${OLDDIR}/misc/cgo/$f | |
187 | newfile=${NEWDIR}/misc/cgo/$f | |
188 | libgofile=misc/cgo/$f | |
189 | merge $f ${oldfile} ${newfile} ${libgofile} | |
190 | done | |
191 | ||
f11c2155 | 192 | (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do |
193 | oldfile=${OLDDIR}/src/$f | |
194 | newfile=${NEWDIR}/src/$f | |
e440a328 | 195 | libgofile=go/$f |
196 | if test -f ${newfile}; then | |
197 | continue | |
198 | fi | |
199 | if ! test -f ${libgofile}; then | |
200 | continue | |
201 | fi | |
202 | echo "merge.sh: ${libgofile}: REMOVED" | |
203 | rm -f ${libgofile} | |
4a3da3a8 | 204 | git rm ${libgofile} |
e440a328 | 205 | done |
206 | ||
aaff1ad7 | 207 | (cd ${OLDDIR}/misc/cgo && find . -type f -print) | while read f; do |
208 | oldfile=${OLDDIR}/misc/cgo/$f | |
209 | newfile=${NEWDIR}/misc/cgo/$f | |
210 | libgofile=misc/cgo/$f | |
211 | if test -f ${newfile}; then | |
212 | continue | |
213 | fi | |
214 | if ! test -f ${libgofile}; then | |
215 | continue | |
216 | fi | |
217 | echo "merge.sh: ${libgofile}: REMOVED" | |
218 | rm -f ${libgofile} | |
219 | git rm ${libgofile} | |
220 | done | |
221 | ||
e440a328 | 222 | (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp |
223 | mv MERGE.tmp MERGE |