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"
76 elif test -f ${old}; then
77 # The file exists in the old version.
78 if ! test -f ${libgo}; then
79 if ! cmp -s ${old} ${new}; then
80 echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
84 if cmp -s ${old} ${libgo}; then
85 # The libgo file is unchanged from the old version.
86 if cmp -s ${new} ${libgo}; then
87 # File is unchanged from old to new version.
90 # Update file in libgo.
91 echo "merge.sh: $name: updating"
94 # The libgo file has local changes.
96 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
101 echo "merge.sh: $name: updating"
102 mv ${libgo}.tmp
${libgo}
105 echo "merge.sh: $name: CONFLICTS"
106 mv ${libgo}.tmp
${libgo}
109 echo 1>&2 "merge.sh: $name: DIFF3 FAILURE"
114 # The file does not exist in the old version.
115 if test -f ${libgo}; then
116 if ! cmp -s ${new} ${libgo}; then
117 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
120 echo "merge.sh: $name: NEW"
121 dir
=`dirname ${libgo}`
122 if ! test -d ${dir}; then
130 echo ${rev} > VERSION
132 (cd ${NEWDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
135 .
/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
/quoted
/* | .
/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 | .
/cmd
/vendor
/golang.org
/x
/sync
/semaphore
)
144 if test "$skip" = "true"; then
148 oldfile
=${OLDDIR}/src
/$f
149 newfile
=${NEWDIR}/src
/$f
150 libgofile
=go
/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
151 merge
$f ${oldfile} ${newfile} ${libgofile}
154 (cd ${NEWDIR}/src
&& find .
-name 'go.mod' -print) |
while read f
; do
155 oldfile
=${OLDDIR}/src
/$f
156 newfile
=${NEWDIR}/src
/$f
157 libgofile
=go
/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
158 merge
$f ${oldfile} ${newfile} ${libgofile}
161 (cd ${NEWDIR}/src
&& find .
-name 'modules.txt' -print) |
while read f
; do
162 oldfile
=${OLDDIR}/src
/$f
163 newfile
=${NEWDIR}/src
/$f
165 merge
$f ${oldfile} ${newfile} ${libgofile}
168 (cd ${NEWDIR}/src
&& find .
-name testdata
-print) |
while read d
; do
171 .
/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
/*)
176 .
/runtime
/race
/* | .
/runtime
/cgo
/*)
180 if test "$skip" = "true"; then
184 oldtd
=${OLDDIR}/src
/$d
185 newtd
=${NEWDIR}/src
/$d
186 libgotd
=go
/`echo $d | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
187 if ! test -d ${oldtd}; then
188 echo "merge.sh: $d: NEWDIR"
191 (cd ${oldtd} && git ls-files .
) |
while read f
; do
192 if test "`basename -- $f`" = ".gitignore"; then
198 libgofile
=${libgotd}/$f
199 merge
${name} ${oldfile} ${newfile} ${libgofile}
201 (cd ${newtd} && git ls-files .
) |
while read f
; do
202 if test "`basename -- $f`" = ".gitignore"; then
206 if ! test -f ${oldfile}; then
209 libgofile
=${libgotd}/$f
210 merge
${name} ${oldfile} ${newfile} ${libgofile}
215 (cd ${NEWDIR}/misc
/cgo
&& find .
-type f
-print) |
while read f
; do
216 oldfile
=${OLDDIR}/misc
/cgo
/$f
217 newfile
=${NEWDIR}/misc
/cgo
/$f
218 libgofile
=misc
/cgo
/$f
219 merge
$f ${oldfile} ${newfile} ${libgofile}
222 (cd ${OLDDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
223 oldfile
=${OLDDIR}/src
/$f
224 newfile
=${NEWDIR}/src
/$f
226 if test -f ${newfile}; then
229 if ! test -f ${libgofile}; then
232 echo "merge.sh: ${libgofile}: REMOVED"
236 (cd ${OLDDIR}/misc
/cgo
&& find .
-type f
-print) |
while read f
; do
237 oldfile
=${OLDDIR}/misc
/cgo
/$f
238 newfile
=${NEWDIR}/misc
/cgo
/$f
239 libgofile
=misc
/cgo
/$f
240 if test -f ${newfile}; then
243 if ! test -f ${libgofile}; then
246 echo "merge.sh: ${libgofile}: REMOVED"
250 (echo ${new_rev}; sed -ne '2,$p' MERGE
) > MERGE.tmp