merge.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 Git 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 git-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 -d ${new}; then
  44. if ! test -d ${old}; then
  45. if test -f ${old}; then
  46. echo 1>&2 "merge.sh: ${name}: FILE BECAME DIRECTORY"
  47. fi
  48. fi
  49. elif ! test -f ${new}; then
  50. # The file does not exist in the new version.
  51. if ! test -f ${old}; then
  52. echo 1>&2 "merge.sh internal error no files $old $new"
  53. exit 1
  54. fi
  55. if ! test -f ${libgo}; then
  56. # File removed in new version and libgo.
  57. :;
  58. else
  59. echo "merge.sh: ${name}: REMOVED"
  60. rm -f ${libgo}
  61. fi
  62. elif test -f ${old}; then
  63. # The file exists in the old version.
  64. if ! test -f ${libgo}; then
  65. if ! cmp -s ${old} ${new}; then
  66. echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
  67. fi
  68. return
  69. fi
  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.
  74. return
  75. fi
  76. # Update file in libgo.
  77. echo "merge.sh: $name: updating"
  78. cp ${new} ${libgo}
  79. else
  80. # The libgo file has local changes.
  81. set +e
  82. diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
  83. status=$?
  84. set -e
  85. case $status in
  86. 0)
  87. echo "merge.sh: $name: updating"
  88. mv ${libgo}.tmp ${libgo}
  89. ;;
  90. 1)
  91. echo "merge.sh: $name: CONFLICTS"
  92. mv ${libgo}.tmp ${libgo}
  93. ;;
  94. *)
  95. echo 1>&2 "merge.sh: $name: DIFF3 FAILURE"
  96. ;;
  97. esac
  98. fi
  99. else
  100. # The file does not exist in the old version.
  101. if test -f ${libgo}; then
  102. if ! cmp -s ${new} ${libgo}; then
  103. echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
  104. fi
  105. else
  106. echo "merge.sh: $name: NEW"
  107. dir=`dirname ${libgo}`
  108. if ! test -d ${dir}; then
  109. mkdir -p ${dir}
  110. fi
  111. cp ${new} ${libgo}
  112. fi
  113. fi
  114. }
  115. echo ${rev} > VERSION
  116. (cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
  117. skip=false
  118. case "$f" in
  119. ./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)
  120. ;;
  121. ./cmd/*)
  122. skip=true
  123. ;;
  124. ./runtime/race/*)
  125. skip=true
  126. ;;
  127. esac
  128. if test "$skip" = "true"; then
  129. continue
  130. fi
  131. oldfile=${OLDDIR}/src/$f
  132. newfile=${NEWDIR}/src/$f
  133. libgofile=go/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
  134. merge $f ${oldfile} ${newfile} ${libgofile}
  135. done
  136. (cd ${NEWDIR}/src && find . -name 'go.mod' -print) | while read f; do
  137. oldfile=${OLDDIR}/src/$f
  138. newfile=${NEWDIR}/src/$f
  139. libgofile=go/`echo $f | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
  140. merge $f ${oldfile} ${newfile} ${libgofile}
  141. done
  142. (cd ${NEWDIR}/src && find . -name 'modules.txt' -print) | while read f; do
  143. oldfile=${OLDDIR}/src/$f
  144. newfile=${NEWDIR}/src/$f
  145. libgofile=go/$f
  146. merge $f ${oldfile} ${newfile} ${libgofile}
  147. done
  148. (cd ${NEWDIR}/src && find . -name testdata -print) | while read d; do
  149. skip=false
  150. case "$d" in
  151. ./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/*)
  152. ;;
  153. ./cmd/*)
  154. skip=true
  155. ;;
  156. ./runtime/race/* | ./runtime/cgo/*)
  157. skip=true
  158. ;;
  159. esac
  160. if test "$skip" = "true"; then
  161. continue
  162. fi
  163. oldtd=${OLDDIR}/src/$d
  164. newtd=${NEWDIR}/src/$d
  165. libgotd=go/`echo $d | sed -e 's|cmd/vendor/|/|' | sed -e 's|/vendor/|/|'`
  166. if ! test -d ${oldtd}; then
  167. echo "merge.sh: $d: NEWDIR"
  168. continue
  169. fi
  170. (cd ${oldtd} && git ls-files .) | while read f; do
  171. if test "`basename -- $f`" = ".gitignore"; then
  172. continue
  173. fi
  174. name=$d/$f
  175. oldfile=${oldtd}/$f
  176. newfile=${newtd}/$f
  177. libgofile=${libgotd}/$f
  178. merge ${name} ${oldfile} ${newfile} ${libgofile}
  179. done
  180. (cd ${newtd} && git ls-files .) | while read f; do
  181. if test "`basename -- $f`" = ".gitignore"; then
  182. continue
  183. fi
  184. oldfile=${oldtd}/$f
  185. if ! test -f ${oldfile}; then
  186. name=$d/$f
  187. newfile=${newtd}/$f
  188. libgofile=${libgotd}/$f
  189. merge ${name} ${oldfile} ${newfile} ${libgofile}
  190. fi
  191. done
  192. done
  193. (cd ${NEWDIR}/misc/cgo && find . -type f -print) | while read f; do
  194. oldfile=${OLDDIR}/misc/cgo/$f
  195. newfile=${NEWDIR}/misc/cgo/$f
  196. libgofile=misc/cgo/$f
  197. merge $f ${oldfile} ${newfile} ${libgofile}
  198. done
  199. (cd ${OLDDIR}/src && find . -name '*.go' -print) | while read f; do
  200. oldfile=${OLDDIR}/src/$f
  201. newfile=${NEWDIR}/src/$f
  202. libgofile=go/$f
  203. if test -f ${newfile}; then
  204. continue
  205. fi
  206. if ! test -f ${libgofile}; then
  207. continue
  208. fi
  209. echo "merge.sh: ${libgofile}: REMOVED"
  210. rm -f ${libgofile}
  211. done
  212. (cd ${OLDDIR}/misc/cgo && find . -type f -print) | while read f; do
  213. oldfile=${OLDDIR}/misc/cgo/$f
  214. newfile=${NEWDIR}/misc/cgo/$f
  215. libgofile=misc/cgo/$f
  216. if test -f ${newfile}; then
  217. continue
  218. fi
  219. if ! test -f ${libgofile}; then
  220. continue
  221. fi
  222. echo "merge.sh: ${libgofile}: REMOVED"
  223. rm -f ${libgofile}
  224. done
  225. (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
  226. mv MERGE.tmp MERGE