|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +version=0.20 |
| 4 | +program=${0##*/} |
| 5 | +progdir=${0%/*} |
| 6 | +if [ "$progdir" = "$program" ]; then progdir="."; fi |
| 7 | + |
| 8 | +# ---------------------------------------------------------------------- |
| 9 | +function usage() { |
| 10 | + cat <<EOF |
| 11 | +NAME |
| 12 | + $program - merge and commit a sprint branch |
| 13 | +
|
| 14 | +SYNOPSIS |
| 15 | + $program [OPTIONS] BRANCH SVNREV |
| 16 | +
|
| 17 | +DESCRIPTION |
| 18 | + Merge and commit a sprint branch |
| 19 | +
|
| 20 | +EOF |
| 21 | + echo -e "OPTIONS" |
| 22 | + if [ "$(uname)" = "Linux" ]; then |
| 23 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | tr -s "\t|" "\t," | sed -r -e 's/\)[ \t]+([A-Z]+)=\$2[^#]*#/=\1\t/' -e 's/\)[^#]*#/\t/' |
| 24 | + else |
| 25 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /' |
| 26 | + fi |
| 27 | + cat <<EOF |
| 28 | +
|
| 29 | +FILES |
| 30 | +
|
| 31 | +AUTHOR |
| 32 | + Written by Henrik Levkowetz, <henrik@tools.ietf.org> |
| 33 | +
|
| 34 | +COPYRIGHT |
| 35 | + Copyright 2010 Henrik Levkowetz. |
| 36 | +
|
| 37 | + This program is free software; you can redistribute it and/or modify |
| 38 | + it under the terms of the GNU General Public License as published by |
| 39 | + the Free Software Foundation; either version 2 of the License, or (at |
| 40 | + your option) any later version. There is NO WARRANTY; not even the |
| 41 | + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 42 | + PURPOSE. See the GNU General Public License for more details. |
| 43 | + |
| 44 | +EOF |
| 45 | + |
| 46 | +} |
| 47 | + |
| 48 | +# ---------------------------------------------------------------------- |
| 49 | +function die() { |
| 50 | + echo -e "\n$program: error: $*" > /dev/stderr |
| 51 | + exit 1 |
| 52 | +} |
| 53 | + |
| 54 | +function note() { |
| 55 | + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi |
| 56 | +} |
| 57 | + |
| 58 | +# ---------------------------------------------------------------------- |
| 59 | +function version() { |
| 60 | + echo -e "$program $version" |
| 61 | +} |
| 62 | + |
| 63 | +# ---------------------------------------------------------------------- |
| 64 | +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR |
| 65 | + |
| 66 | + |
| 67 | +# ---------------------------------------------------------------------- |
| 68 | +# Option parsing |
| 69 | + |
| 70 | +# Options |
| 71 | +shortopts=chvV |
| 72 | +longopts=commit,help,verbose,version |
| 73 | + |
| 74 | +# Default values |
| 75 | + |
| 76 | +if [ "$(uname)" = "Linux" ]; then |
| 77 | + args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@") |
| 78 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 79 | + eval set -- "$args" |
| 80 | + sed="sed -r" |
| 81 | +else |
| 82 | + # Darwin, BSDs |
| 83 | + args=$(getopt -o$shortopts $SV $*) |
| 84 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 85 | + set -- $args |
| 86 | + sed="sed -E" |
| 87 | +fi |
| 88 | + |
| 89 | +while true ; do |
| 90 | + case "$1" in |
| 91 | + -c| --commit) ARG_COMMIT=1;; # Run commit in addition to merge |
| 92 | + -h| --help) usage; exit;; # Show this help, then exit |
| 93 | + -v| --verbose) VERBOSE=1;; # Be more talkative |
| 94 | + -V| --version) version; exit;; # Show program version, then exit |
| 95 | + --) shift; break;; |
| 96 | + *) die "Internal error, inconsistent option specification: '$1'";; |
| 97 | + esac |
| 98 | + shift |
| 99 | +done |
| 100 | + |
| 101 | +# ---------------------------------------------------------------------- |
| 102 | +# The program itself |
| 103 | + |
| 104 | +[[ $1 =~ @ ]] && set ${1/@/ } |
| 105 | +[ $# -ge 2 ] || die "Expected branch and repository revision on the command line" |
| 106 | +[ ${PWD##*/} = trunk ] || die "Expected this script to be run in trunk" |
| 107 | +branch=$1 |
| 108 | +rev=$2 |
| 109 | +fix=$3 |
| 110 | + |
| 111 | +note "Extract who and what:" |
| 112 | +info=$(svn log http://svn.tools.ietf.org/svn/tools/ietfdb/ -r $rev --incremental) |
| 113 | +set $(echo "$info" | tail -n +2 | head -n 1 | tr "|" "\t") |
| 114 | +who=$2; echo -e "\n$who" |
| 115 | +comment=$(echo "$info" | tail -n +3); echo -e "$comment\n" |
| 116 | + |
| 117 | +note "Do the merge:" |
| 118 | +svn merge -c $rev http://svn.tools.ietf.org/svn/tools/ietfdb/personal/$branch . |
| 119 | + |
| 120 | +mail -s "Merged datatracker branch personal/$branch@$rev to trunk" $who -c henrik@levkowetz.com <<-EOF |
| 121 | +Hi, |
| 122 | +
|
| 123 | +This is an automatic merge info message. Your code in personal/$branch@$rev |
| 124 | +has been merged to trunk, and will be part of the next release if nothing |
| 125 | +goes wrong during final testing. |
| 126 | +
|
| 127 | +Regards, |
| 128 | +
|
| 129 | + Henrik |
| 130 | + (via the mergesprintbranch script) |
| 131 | +EOF |
| 132 | + |
| 133 | +if [ "$ARG_COMMIT" ]; then |
| 134 | + echo "Committing the merge:" |
| 135 | + echo "" |
| 136 | + svn commit -m "Merged [$rev] from $who: $comment $fix" |
| 137 | +else |
| 138 | + echo "This merge has not been committed yet." |
| 139 | + echo "To commit it, run this commit command:" |
| 140 | + echo "" |
| 141 | + echo "svn commit -m \"Merged [$rev] from $who: $comment $fix\"" |
| 142 | +fi |
| 143 | + |
0 commit comments