merge.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/sh
  2. # Copyright 2009 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # This script merges changes from the master copy of the Go library
  6. # into the libgo library. This does the easy stuff; the hard stuff is
  7. # left to the user.
  8. # The file MERGE should hold the Mercurial revision number of the last
  9. # revision which was merged into these sources. Given that, and given
  10. # the current sources, we can run the usual diff3 algorithm to merge
  11. # all changes into our sources.
  12. set -e
  13. TMPDIR=${TMPDIR:-/tmp}
  14. OLDDIR=${TMPDIR}/libgo-merge-old
  15. NEWDIR=${TMPDIR}/libgo-merge-new
  16. if ! test -f MERGE; then
  17. echo 1>&2 "merge.sh: must be run in libgo source directory"
  18. exit 1
  19. fi
  20. rev=weekly
  21. case $# in
  22. 1) ;;
  23. 2) rev=$2 ;;
  24. *)
  25. echo 1>&2 "merge.sh: Usage: merge.sh mercurial-repository [revision]"
  26. exit 1
  27. ;;
  28. esac
  29. repository=$1
  30. old_rev=`sed 1q MERGE`
  31. rm -rf ${OLDDIR}
  32. git clone ${repository} ${OLDDIR}
  33. (cd ${OLDDIR} && git checkout ${old_rev})
  34. rm -rf ${NEWDIR}
  35. git clone ${repository} ${NEWDIR}
  36. (cd ${NEWDIR} && git checkout ${rev})
  37. new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
  38. merge() {
  39. name=$1
  40. old=$2
  41. new=$3
  42. libgo=$4
  43. if ! test -f ${new}; then
  44. # The file does not exist in the new version.
  45. if ! test -f ${old}; then
  46. echo 1>&2 "merge.sh internal error no files $old $new"
  47. exit 1
  48. fi
  49. if ! test -f ${libgo}; then
  50. # File removed in new version and libgo.
  51. :;
  52. else
  53. echo "merge.sh: ${name}: REMOVED"
  54. rm -f ${libgo}
  55. hg rm ${libgo}
  56. fi
  57. elif test -f ${old}; then
  58. # The file exists in the old version.
  59. if ! test -f ${libgo}; then
  60. echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
  61. continue
  62. fi
  63. if cmp -s ${old} ${libgo}; then
  64. # The libgo file is unchanged from the old version.
  65. if cmp -s ${new} ${libgo}; then
  66. # File is unchanged from old to new version.
  67. continue
  68. fi
  69. # Update file in libgo.
  70. echo "merge.sh: $name: updating"
  71. cp ${new} ${libgo}
  72. else
  73. # The libgo file has local changes.
  74. set +e
  75. diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
  76. status=$?
  77. set -e
  78. case $status in
  79. 0)
  80. echo "merge.sh: $name: updating"
  81. mv ${libgo}.tmp ${libgo}
  82. ;;
  83. 1)
  84. echo "merge.sh: $name: CONFLICTS"
  85. mv ${libgo}.tmp ${libgo}
  86. hg resolve -u ${libgo}
  87. ;;
  88. *)
  89. echo 1>&2 "merge.sh: $name: diff3 failure"
  90. exit 1
  91. ;;
  92. esac
  93. fi
  94. else
  95. # The file does not exist in the old version.
  96. if test -f ${libgo}; then
  97. if ! cmp -s ${new} ${libgo}; then
  98. echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
  99. fi
  100. else
  101. echo "merge.sh: $name: NEW"
  102. dir=`dirname ${libgo}`
  103. if ! test -d ${dir}; then
  104. mkdir -p ${dir}
  105. fi
  106. cp ${new} ${libgo}
  107. hg add ${libgo}
  108. fi
  109. fi
  110. }
  111. merge_c() {
  112. from=$1
  113. to=$2
  114. oldfile=${OLDDIR}/src/runtime/$from
  115. if test -f ${oldfile}; then
  116. sed -e 's/·/_/g' < ${oldfile} > ${oldfile}.tmp
  117. oldfile=${oldfile}.tmp
  118. newfile=${NEWDIR}/src/runtime/$from
  119. sed -e 's/·/_/g' < ${newfile} > ${newfile}.tmp
  120. newfile=${newfile}.tmp
  121. libgofile=runtime/$to
  122. merge $from ${oldfile} ${newfile} ${libgofile}
  123. fi
  124. }
  125. if test -f VERSION; then
  126. if ! cmp -s ${NEWDIR}/VERSION VERSION; then
  127. cp ${NEWDIR}/VERSION .
  128. fi
  129. else
  130. if test -f ${NEWDIR}/VERSION; then
  131. cp ${NEWDIR}/VERSION .
  132. fi
  133. fi
  134. (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
  135. oldfile=${OLDDIR}/src/$f
  136. newfile=${NEWDIR}/src/$f
  137. libgofile=go/$f
  138. merge $f ${oldfile} ${newfile} ${libgofile}
  139. done
  140. (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
  141. oldtd=${OLDDIR}/src/$d
  142. newtd=${NEWDIR}/src/$d
  143. libgotd=go/$d
  144. if ! test -d ${oldtd}; then
  145. continue
  146. fi
  147. (cd ${oldtd} && git ls-files .) | while read f; do
  148. if test "`basename $f`" = ".gitignore"; then
  149. continue
  150. fi
  151. name=$d/$f
  152. oldfile=${oldtd}/$f
  153. newfile=${newtd}/$f
  154. libgofile=${libgotd}/$f
  155. merge ${name} ${oldfile} ${newfile} ${libgofile}
  156. done
  157. done
  158. cmdlist="cgo go gofmt"
  159. for c in $cmdlist; do
  160. (cd ${NEWDIR}/src/cmd/$c && find . -name '*.go' -print) | while read f; do
  161. oldfile=${OLDDIR}/src/cmd/$c/$f
  162. newfile=${NEWDIR}/src/cmd/$c/$f
  163. libgofile=go/cmd/$c/$f
  164. merge $f ${oldfile} ${newfile} ${libgofile}
  165. done
  166. (cd ${NEWDIR}/src/cmd/$c && find . -name testdata -print) | while read d; do
  167. oldtd=${OLDDIR}/src/cmd/$c/$d
  168. newtd=${NEWDIR}/src/cmd/$c/$d
  169. libgotd=go/cmd/$c/$d
  170. if ! test -d ${oldtd}; then
  171. continue
  172. fi
  173. (cd ${oldtd} && git ls-files .) | while read f; do
  174. if test "`basename $f`" = ".gitignore"; then
  175. continue
  176. fi
  177. name=$d/$f
  178. oldfile=${oldtd}/$f
  179. newfile=${newtd}/$f
  180. libgofile=${libgotd}/$f
  181. merge ${name} ${oldfile} ${newfile} ${libgofile}
  182. done
  183. done
  184. done
  185. runtime="chan.goc chan.h cpuprof.goc env_posix.c heapdump.c lock_futex.c lfstack.goc lock_sema.c mcache.c mcentral.c mfixalloc.c mgc0.c mgc0.h mheap.c msize.c netpoll.goc netpoll_epoll.c netpoll_kqueue.c netpoll_stub.c panic.c print.c proc.c race.h rdebug.goc runtime.c runtime.h signal_unix.c signal_unix.h malloc.h malloc.goc mprof.goc parfor.c runtime1.goc sema.goc sigqueue.goc string.goc time.goc"
  186. for f in $runtime; do
  187. # merge_c $f $f
  188. true
  189. done
  190. # merge_c os_linux.c thread-linux.c
  191. # merge_c mem_linux.c mem.c
  192. (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do
  193. oldfile=${OLDDIR}/src/$f
  194. newfile=${NEWDIR}/src/$f
  195. libgofile=go/$f
  196. if test -f ${newfile}; then
  197. continue
  198. fi
  199. if ! test -f ${libgofile}; then
  200. continue
  201. fi
  202. echo "merge.sh: ${libgofile}: REMOVED"
  203. rm -f ${libgofile}
  204. hg rm ${libgofile}
  205. done
  206. (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
  207. mv MERGE.tmp MERGE