| 1 | #! /bin/sh -e |
| 2 | |
| 3 | fail () { |
| 4 | echo >&2 "$0: $*" |
| 5 | exit 1 |
| 6 | } |
| 7 | |
| 8 | usage () { |
| 9 | echo "usage: $0 [-c] [UPSTREAM BUILDABLE]" |
| 10 | } |
| 11 | |
| 12 | fail_usage () { |
| 13 | usage >&2 |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | ## Parse the command-line. |
| 18 | bogusp=nil createp=nil |
| 19 | unset head new |
| 20 | while getopts "ch" opt; do |
| 21 | case $opt in |
| 22 | h) usage; exit 0 ;; |
| 23 | c) createp=t ;; |
| 24 | *) bogusp=t ;; |
| 25 | esac |
| 26 | done |
| 27 | shift $(( $OPTIND - 1 )) |
| 28 | case $# in 0) ;; 1) bogusp=t ;; *) head=$1 new=$2; shift 2 ;; esac |
| 29 | case $# in 0) ;; *) bogusp=t ;; esac |
| 30 | case $bogusp in nil) ;; *) fail_usage ;; esac |
| 31 | |
| 32 | ## Get the current branch name. |
| 33 | case ${head+t} in |
| 34 | t) ;; |
| 35 | *) |
| 36 | head=$(git symbolic-ref HEAD) |
| 37 | case $head in |
| 38 | refs/heads/*) head=${head#refs/heads/} ;; |
| 39 | *) fail "HEAD is not at a branch head" ;; |
| 40 | esac |
| 41 | case $head in |
| 42 | buildable/*) fail "upstream is already a buildable branch" ;; |
| 43 | esac |
| 44 | ;; |
| 45 | esac |
| 46 | |
| 47 | ## Get the output branch name. |
| 48 | case ${new+t} in |
| 49 | t) ;; |
| 50 | *) |
| 51 | new=buildable/$head |
| 52 | ;; |
| 53 | esac |
| 54 | case $createp in |
| 55 | t) |
| 56 | if git rev-parse $new -- >/dev/null 2>&1; then |
| 57 | fail "branch $new already exists" |
| 58 | fi |
| 59 | old=0000000000000000000000000000000000000000 |
| 60 | ;; |
| 61 | nil) |
| 62 | old=$(git rev-parse $new --) |
| 63 | ;; |
| 64 | esac |
| 65 | |
| 66 | ## Make a temporary place. |
| 67 | git=$(git rev-parse --git-dir) |
| 68 | git=$(cd $git && pwd) |
| 69 | dir=$(mktemp -d) |
| 70 | trap "cd; rm -rf \"$dir\"" EXIT INT TERM |
| 71 | cd "$dir" |
| 72 | mkdir work tmp |
| 73 | |
| 74 | ## Make a nice clean checkout. |
| 75 | GIT_INDEX_FILE=$dir/idx; export GIT_INDEX_FILE |
| 76 | GIT_DIR=$git; export GIT_DIR |
| 77 | GIT_WORK_TREE=$dir/work; export GIT_WORK_TREE |
| 78 | git read-tree "$head^{}" |
| 79 | git checkout-index --all |
| 80 | |
| 81 | ## Go in, and set stuff up. The business with `RELEASE' is kinda scungy. |
| 82 | ## Sorry 'bout that. |
| 83 | cd work |
| 84 | if ! ver=$(git describe --abbrev=4 "$head^{}" 2>/dev/null); then |
| 85 | ver=UNKNOWN |
| 86 | fi |
| 87 | echo "$ver" >RELEASE |
| 88 | mdw-setup |
| 89 | rm -rf autom4te.cache/ RELEASE |
| 90 | |
| 91 | ## Pick through newly added symlinks and snap them to real files. |
| 92 | git ls-files -o | while read f; do |
| 93 | if [ -L "$f" ]; then |
| 94 | cp "$f" ../tmp/snap |
| 95 | mv ../tmp/snap "$f" |
| 96 | fi |
| 97 | done |
| 98 | |
| 99 | ## Add the new files to the tree. |
| 100 | commit () { |
| 101 | tree=$1; shift |
| 102 | case $createp in |
| 103 | t) git commit-tree -p "$head^{}" "$@" $tree ;; |
| 104 | nil) git commit-tree -p "$new" -p "$head^{}" "$@" $tree ;; |
| 105 | esac |
| 106 | } |
| 107 | git ls-files -oz | xargs -0r git add -f |
| 108 | tree=$(git write-tree) |
| 109 | commit=$(commit $tree -m "Update automatically managed build utilities.") |
| 110 | git update-ref "refs/heads/$new" $commit $old |