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 -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"
63 if ! test -f ${libgo}; then
64 # File removed in new version and libgo.
67 echo "merge.sh: ${name}: REMOVED"
71 elif test -f ${old}; then
72 # The file exists in the old version.
73 if ! test -f ${libgo}; then
74 if ! cmp -s ${old} ${new}; then
75 echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
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.
85 # Update file in libgo.
86 echo "merge.sh: $name: updating"
89 # The libgo file has local changes.
91 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
96 echo "merge.sh: $name: updating"
97 mv ${libgo}.tmp
${libgo}
100 echo "merge.sh: $name: CONFLICTS"
101 mv ${libgo}.tmp
${libgo}
104 echo 1>&2 "merge.sh: $name: DIFF3 FAILURE"
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"
115 echo "merge.sh: $name: NEW"
116 dir
=`dirname ${libgo}`
117 if ! test -d ${dir}; then
126 echo ${rev} > VERSION
128 (cd ${NEWDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
131 .
/cmd
/cgo
/* | .
/cmd
/go
/* | .
/cmd
/gofmt
/* | .
/cmd
/internal
/browser
/*)
140 if test "$skip" = "true"; then
144 oldfile
=${OLDDIR}/src
/$f
145 newfile
=${NEWDIR}/src
/$f
146 libgofile
=go
/`echo $f | sed -e 's|/vendor/|/|'`
147 merge
$f ${oldfile} ${newfile} ${libgofile}
150 (cd ${NEWDIR}/src
&& find .
-name testdata
-print) |
while read d
; do
153 .
/cmd
/cgo
/* | .
/cmd
/go
/* | .
/cmd
/gofmt
/* | .
/cmd
/internal
/browser
/*)
162 if test "$skip" = "true"; then
166 oldtd
=${OLDDIR}/src
/$d
167 newtd
=${NEWDIR}/src
/$d
169 if ! test -d ${oldtd}; then
170 echo "merge.sh: $d: NEWDIR"
173 (cd ${oldtd} && git ls-files .
) |
while read f
; do
174 if test "`basename $f`" = ".gitignore"; then
180 libgofile
=${libgotd}/$f
181 merge
${name} ${oldfile} ${newfile} ${libgofile}
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}
192 (cd ${OLDDIR}/src
&& find .
-name '*.go' -print) |
while read f
; do
193 oldfile
=${OLDDIR}/src
/$f
194 newfile
=${NEWDIR}/src
/$f
196 if test -f ${newfile}; then
199 if ! test -f ${libgofile}; then
202 echo "merge.sh: ${libgofile}: REMOVED"
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
214 if ! test -f ${libgofile}; then
217 echo "merge.sh: ${libgofile}: REMOVED"
222 (echo ${new_rev}; sed -ne '2,$p' MERGE
) > MERGE.tmp