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"
28 if test $# -ne 1; then
29 echo 1>&2 "merge.sh: Usage: merge.sh mercurial-repository"
35 old_rev
=`sed 1q MERGE`
38 hg clone
-r ${old_rev} ${repository} ${OLDDIR}
41 hg clone
-u release
${repository} ${NEWDIR}
43 new_rev
=`cd ${NEWDIR} && hg log -r release | sed 1q | sed -e 's/.*://'`
50 if ! test -f ${new}; then
51 # The file does not exist in the new version.
52 if ! test -f ${old}; then
53 echo 1>&2 "merge.sh internal error no files $old $new"
56 if ! test -f ${libgo}; then
57 # File removed in new version and libgo.
60 echo "merge.sh: ${name}: REMOVED"
64 elif test -f ${old}; then
65 # The file exists in the old version.
66 if ! test -f ${libgo}; then
67 echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
70 if cmp -s ${old} ${libgo}; then
71 # The libgo file is unchanged from the old version.
72 if cmp -s ${new} ${libgo}; then
73 # File is unchanged from old to new version.
76 # Update file in libgo.
77 echo "merge.sh: $name: updating"
80 # The libgo file has local changes.
82 diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
87 echo "merge.sh: $name: updating"
88 mv ${libgo}.tmp
${libgo}
91 echo "merge.sh: $name: CONFLICTS"
92 mv ${libgo}.tmp
${libgo}
93 hg resolve
-u ${libgo}
96 echo 1>&2 "merge.sh: $name: diff3 failure"
102 # The file does not exist in the old version.
103 if test -f ${libgo}; then
104 if ! cmp -s ${new} ${libgo}; then
105 echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
108 echo "merge.sh: $name: NEW"
109 dir
=`dirname ${libgo}`
110 if ! test -d ${dir}; then
119 (cd ${NEWDIR}/src
/pkg
&& find .
-name '*.go' -print) |
while read f
; do
120 if test `dirname $f` = "./syscall"; then
123 oldfile
=${OLDDIR}/src
/pkg
/$f
124 newfile
=${NEWDIR}/src
/pkg
/$f
126 merge
$f ${oldfile} ${newfile} ${libgofile}
129 (cd ${NEWDIR}/src
/pkg
&& find .
-name testdata
-print) |
while read d
; do
130 oldtd
=${OLDDIR}/src
/pkg
/$d
131 newtd
=${NEWDIR}/src
/pkg
/$d
133 if ! test -d ${oldtd}; then
136 (cd ${oldtd} && hg status
-A .
) |
while read f
; do
137 if test "`basename $f`" = ".hgignore"; then
140 f
=`echo $f | sed -e 's/^..//'`
144 libgofile
=${libgotd}/$f
145 merge
${name} ${oldfile} ${newfile} ${libgofile}
149 runtime
="goc2c.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c malloc.h malloc.goc mprof.goc"
150 for f
in $runtime; do
151 oldfile
=${OLDDIR}/src
/pkg
/runtime
/$f
152 newfile
=${NEWDIR}/src
/pkg
/runtime
/$f
154 merge
$f ${oldfile} ${newfile} ${libgofile}
157 (cd ${OLDDIR}/src
/pkg
&& find .
-name '*.go' -print) |
while read f
; do
158 oldfile
=${OLDDIR}/src
/pkg
/$f
159 newfile
=${NEWDIR}/src
/pkg
/$f
161 if test -f ${newfile}; then
164 if ! test -f ${libgofile}; then
167 echo "merge.sh: ${libgofile}: REMOVED"
172 (echo ${new_rev}; sed -ne '2,$p' MERGE
) > MERGE.tmp