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.
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
11 # The file MERGE should hold the Git revision number of the last
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.
18 TMPDIR
=${TMPDIR:-/tmp}
20 OLDDIR
=${TMPDIR}/libgo-merge-old
21 NEWDIR
=${TMPDIR}/libgo-merge-new
23 if ! test -f MERGE
; then
24 echo 1>&2 "merge.sh: must be run in libgo source directory"
33 echo 1>&2 "merge.sh: Usage: merge.sh git-repository [revision]"
40 old_rev
=`sed 1q MERGE`
43 git clone
${repository} ${OLDDIR}
44 (cd ${OLDDIR} && git checkout
${old_rev})
47 git clone
${repository} ${NEWDIR}
48 (cd ${NEWDIR} && git checkout
${rev})
50 new_rev
=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
57 if test -d ${new}; then
58 if ! test -d ${old}; then
59 if test -f ${old}; then
60 echo 1>&2 "merge.sh: ${name}: FILE BECAME DIRECTORY"
63 elif ! test -f ${new}; then
64 # The file does not exist in the new version.
65 if ! test -f ${old}; then
66 echo 1>&2 "merge.sh internal error no files $old $new"
69 if ! test -f ${libgo}; then
70 # File removed in new version and libgo.
73 echo "merge.sh: ${name}: REMOVED"
77 elif test -f ${old}; then
78 # The file exists in the old version.
79 if ! test -f ${libgo}; then
80 if ! cmp -s ${old} ${new}; then
81 echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
85 if cmp -s ${old} ${libgo}; then
86 # The libgo file is unchanged from the old version.
87 if cmp -s ${new} ${libgo}; then
88 # File is unchanged from old to new version.
91 # Update file in libgo.
92 echo "merge.sh: $name: updating"
95 # The libgo file has local changes.
97 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
102 echo "merge.sh: $name: updating"
103 mv ${libgo}.tmp
${libgo}
106 echo "merge.sh: $name: CONFLICTS"
107 mv ${libgo}.tmp
${libgo}
110 echo 1>&2 "merge.sh: $name: DIFF3 FAILURE"
115 # The file does not exist in the old version.
116 if test -f ${libgo}; then
117 if ! cmp -s ${new} ${libgo}; then
118 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
121 echo "merge.sh: $name: NEW"
122 dir
=`dirname ${libgo}`
123 if ! test -d ${dir}; then
132 echo ${rev} > VERSION
134 (cd ${NEWDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
137 .
/cmd
/buildid
/* | .
/cmd
/cgo
/* | .
/cmd
/go
/* | .
/cmd
/gofmt
/* | .
/cmd
/test2json
/* | .
/cmd
/vet
/* | .
/cmd
/internal
/browser
/* | .
/cmd
/internal
/buildid
/* | .
/cmd
/internal
/codesign
/* | .
/cmd
/internal
/edit
/* | .
/cmd
/internal
/objabi
/* | .
/cmd
/internal
/test2json
/* | .
/cmd
/internal
/sys
/* | .
/cmd
/internal
/traceviewer
/* | .
/cmd
/vendor
/golang.org
/x
/tools
/* | .
/cmd
/vendor
/golang.org
/x
/mod
/* | .
/cmd
/vendor
/golang.org
/x
/xerrors
/* | .
/cmd
/vendor
/golang.org
/x
/crypto
/ed25519
)
146 if test "$skip" = "true"; then
150 oldfile
=${OLDDIR}/src
/$f
151 newfile
=${NEWDIR}/src
/$f
152 libgofile
=go
/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
153 merge
$f ${oldfile} ${newfile} ${libgofile}
156 (cd ${NEWDIR}/src
&& find .
-name 'go.mod' -print) |
while read f
; do
157 oldfile
=${OLDDIR}/src
/$f
158 newfile
=${NEWDIR}/src
/$f
159 libgofile
=go
/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
160 merge
$f ${oldfile} ${newfile} ${libgofile}
163 (cd ${NEWDIR}/src
&& find .
-name 'modules.txt' -print) |
while read f
; do
164 oldfile
=${OLDDIR}/src
/$f
165 newfile
=${NEWDIR}/src
/$f
167 merge
$f ${oldfile} ${newfile} ${libgofile}
170 (cd ${NEWDIR}/src
&& find .
-name testdata
-print) |
while read d
; do
173 .
/cmd
/buildid
/* | .
/cmd
/cgo
/* | .
/cmd
/go
/* | .
/cmd
/gofmt
/* | .
/cmd
/test2json
/* | .
/cmd
/vet
/* | .
/cmd
/internal
/browser
/* | .
/cmd
/internal
/buildid
/* | .
/cmd
/internal
/codesign
/* | .
/cmd
/internal
/diff
/* | .
/cmd
/internal
/edit
/* | .
/cmd
/internal
/objabi
/* | .
/cmd
/internal
/test2json
/* | .
/cmd
/internal
/sys
/* | .
/cmd
/internal
/traceviewer
/* | .
/cmd
/vendor
/golang.org
/x
/tools
/*)
178 .
/runtime
/race
/* | .
/runtime
/cgo
/*)
182 if test "$skip" = "true"; then
186 oldtd
=${OLDDIR}/src
/$d
187 newtd
=${NEWDIR}/src
/$d
188 libgotd
=go
/`echo $d | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
189 if ! test -d ${oldtd}; then
190 echo "merge.sh: $d: NEWDIR"
193 (cd ${oldtd} && git ls-files .
) |
while read f
; do
194 if test "`basename $f`" = ".gitignore"; then
200 libgofile
=${libgotd}/$f
201 merge
${name} ${oldfile} ${newfile} ${libgofile}
205 (cd ${NEWDIR}/misc
/cgo
&& find .
-type f
-print) |
while read f
; do
206 oldfile
=${OLDDIR}/misc
/cgo
/$f
207 newfile
=${NEWDIR}/misc
/cgo
/$f
208 libgofile
=misc
/cgo
/$f
209 merge
$f ${oldfile} ${newfile} ${libgofile}
212 (cd ${OLDDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
213 oldfile
=${OLDDIR}/src
/$f
214 newfile
=${NEWDIR}/src
/$f
216 if test -f ${newfile}; then
219 if ! test -f ${libgofile}; then
222 echo "merge.sh: ${libgofile}: REMOVED"
227 (cd ${OLDDIR}/misc
/cgo
&& find .
-type f
-print) |
while read f
; do
228 oldfile
=${OLDDIR}/misc
/cgo
/$f
229 newfile
=${NEWDIR}/misc
/cgo
/$f
230 libgofile
=misc
/cgo
/$f
231 if test -f ${newfile}; then
234 if ! test -f ${libgofile}; then
237 echo "merge.sh: ${libgofile}: REMOVED"
242 (echo ${new_rev}; sed -ne '2,$p' MERGE
) > MERGE.tmp