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