1#!/bin/sh
2#===-- merge.sh - Test the LLVM release candidates -------------------------===#
3#
4#                     The LLVM Compiler Infrastructure
5#
6# This file is distributed under the University of Illinois Open Source
7# License.
8#
9#===------------------------------------------------------------------------===#
10#
11# Merge a revision into a project.
12#
13#===------------------------------------------------------------------------===#
14
15set -e
16
17rev=""
18proj=""
19revert="no"
20
21function usage() {
22    echo "usage: `basename $0` [OPTIONS]"
23    echo "  -proj PROJECT  The project to merge the result into"
24    echo "  -rev NUM       The revision to merge into the project"
25    echo "  -revert        Revert rather than merge the commit"
26}
27
28while [ $# -gt 0 ]; do
29    case $1 in
30        -rev | --rev | -r )
31            shift
32            rev=$1
33            ;;
34        -proj | --proj | -project | --project | -p )
35            shift
36            proj=$1
37            ;;
38        -h | -help | --help )
39            usage
40            ;;
41        -revert | --revert )
42            revert="yes"
43            ;;
44        * )
45            echo "unknown option: $1"
46            echo ""
47            usage
48            exit 1
49            ;;
50    esac
51    shift
52done
53
54if [ "x$rev" = "x" -o "x$proj" = "x" ]; then
55    echo "error: need to specify project and revision"
56    echo
57    usage
58    exit 1
59fi
60
61if ! svn ls http://llvm.org/svn/llvm-project/$proj/trunk > /dev/null 2>&1 ; then
62    echo "error: invalid project: $proj"
63    exit 1
64fi
65
66tempfile=`mktemp /tmp/merge.XXXXXX` || exit 1
67
68if [ $revert = "yes" ]; then
69    echo "Reverting r$rev:" > $tempfile
70else
71    echo "Merging r$rev:" > $tempfile
72fi
73svn log -c $rev http://llvm.org/svn/llvm-project/$proj/trunk >> $tempfile 2>&1
74
75cd $proj.src
76echo "# Updating tree"
77svn up
78
79if [ $revert = "yes" ]; then
80    echo "# Reverting r$rev in $proj locally"
81    svn merge -c -$rev . || exit 1
82else
83    echo "# Merging r$rev into $proj locally"
84    svn merge -c $rev https://llvm.org/svn/llvm-project/$proj/trunk . || exit 1
85fi
86
87echo
88echo "# To commit, run the following in $proj.src/:"
89echo svn commit -F $tempfile
90
91exit 0
92