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 Mercurial 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 mercurial-repository [revision]"
40 old_rev=`sed 1q MERGE`
43 hg clone -r ${old_rev} ${repository} ${OLDDIR}
46 hg clone -u ${rev} ${repository} ${NEWDIR}
48 new_rev=`cd ${NEWDIR} && hg log -r ${rev} | sed 1q | sed -e 's/.*://'`
55 if ! test -f ${new}; then
56 # The file does not exist in the new version.
57 if ! test -f ${old}; then
58 echo 1>&2 "merge.sh internal error no files $old $new"
61 if ! test -f ${libgo}; then
62 # File removed in new version and libgo.
65 echo "merge.sh: ${name}: REMOVED"
69 elif test -f ${old}; then
70 # The file exists in the old version.
71 if ! test -f ${libgo}; then
72 echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
75 if cmp -s ${old} ${libgo}; then
76 # The libgo file is unchanged from the old version.
77 if cmp -s ${new} ${libgo}; then
78 # File is unchanged from old to new version.
81 # Update file in libgo.
82 echo "merge.sh: $name: updating"
85 # The libgo file has local changes.
87 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
92 echo "merge.sh: $name: updating"
93 mv ${libgo}.tmp ${libgo}
96 echo "merge.sh: $name: CONFLICTS"
97 mv ${libgo}.tmp ${libgo}
98 hg resolve -u ${libgo}
101 echo 1>&2 "merge.sh: $name: diff3 failure"
107 # The file does not exist in the old version.
108 if test -f ${libgo}; then
109 if ! cmp -s ${new} ${libgo}; then
110 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
113 echo "merge.sh: $name: NEW"
114 dir=`dirname ${libgo}`
115 if ! test -d ${dir}; then
124 (cd ${NEWDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
125 if test `dirname $f` = "./syscall"; then
128 oldfile=${OLDDIR}/src/pkg/$f
129 newfile=${NEWDIR}/src/pkg/$f
131 merge $f ${oldfile} ${newfile} ${libgofile}
134 (cd ${NEWDIR}/src/pkg && find . -name testdata -print) | while read d; do
135 oldtd=${OLDDIR}/src/pkg/$d
136 newtd=${NEWDIR}/src/pkg/$d
138 if ! test -d ${oldtd}; then
141 (cd ${oldtd} && hg status -A .) | while read f; do
142 if test "`basename $f`" = ".hgignore"; then
145 f=`echo $f | sed -e 's/^..//'`
149 libgofile=${libgotd}/$f
150 merge ${name} ${oldfile} ${newfile} ${libgofile}
154 runtime="chan.c cpuprof.c goc2c.c lock_futex.c lock_sema.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c proc.c runtime.c runtime.h malloc.h malloc.goc mprof.goc runtime1.goc sema.goc sigqueue.goc string.goc"
155 for f in $runtime; do
156 oldfile=${OLDDIR}/src/pkg/runtime/$f
157 if test -f ${oldfile}; then
158 sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
159 oldfile=${oldfile}.tmp
160 newfile=${NEWDIR}/src/pkg/runtime/$f
161 sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
162 newfile=${newfile}.tmp
164 merge $f ${oldfile} ${newfile} ${libgofile}
168 runtime2="linux/thread.c thread-linux.c linux/mem.c mem.c"
169 echo $runtime2 | while read from; do
171 oldfile=${OLDDIR}/src/pkg/runtime/$from
172 if test -f ${oldfile}; then
173 sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
174 oldfile=${oldfile}.tmp
175 newfile=${NEWDIR}/src/pkg/runtime/$from
176 sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
177 newfile=${newfile}.tmp
178 libgofile=runtime/$to
179 merge $f ${oldfile} ${newfile} ${libgofile}
183 (cd ${OLDDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
184 oldfile=${OLDDIR}/src/pkg/$f
185 newfile=${NEWDIR}/src/pkg/$f
187 if test -f ${newfile}; then
190 if ! test -f ${libgofile}; then
193 echo "merge.sh: ${libgofile}: REMOVED"
198 (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp