|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +version=0.10 |
| 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 - given a patch name and a list of files, create a patch diff |
| 13 | +
|
| 14 | +SYNOPSIS |
| 15 | + $program [OPTIONS] ARGS |
| 16 | +
|
| 17 | +DESCRIPTION |
| 18 | + Given a patch name and a list of changed file, run svn diff to create |
| 19 | + a patch suitable for the patch command, named with the current date |
| 20 | + and the given patch name. Place this in the local patch directory. |
| 21 | + |
| 22 | +
|
| 23 | +EOF |
| 24 | + echo -e "OPTIONS" |
| 25 | + if [ "$(uname)" = "Linux" ]; then |
| 26 | + 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/' |
| 27 | + else |
| 28 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /' |
| 29 | + fi |
| 30 | + cat <<EOF |
| 31 | +
|
| 32 | +FILES |
| 33 | +
|
| 34 | +AUTHOR |
| 35 | + Written by Henrik Levkowetz, <henrik@tools.ietf.org> |
| 36 | +
|
| 37 | +COPYRIGHT |
| 38 | + Copyright 2013 Henrik Levkowetz. |
| 39 | +
|
| 40 | + This program is free software; you can redistribute it and/or modify |
| 41 | + it under the terms of the GNU General Public License as published by |
| 42 | + the Free Software Foundation; either version 2 of the License, or (at |
| 43 | + your option) any later version. There is NO WARRANTY; not even the |
| 44 | + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 45 | + PURPOSE. See the GNU General Public License for more details. |
| 46 | + |
| 47 | +EOF |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +# ---------------------------------------------------------------------- |
| 52 | +function die() { |
| 53 | + echo -e "\n$program: error: $*" > /dev/stderr |
| 54 | + exit 1 |
| 55 | +} |
| 56 | + |
| 57 | +function note() { |
| 58 | + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi |
| 59 | +} |
| 60 | + |
| 61 | +# ---------------------------------------------------------------------- |
| 62 | +function version() { |
| 63 | + echo -e "$program $version" |
| 64 | +} |
| 65 | + |
| 66 | +# ---------------------------------------------------------------------- |
| 67 | +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR |
| 68 | + |
| 69 | + |
| 70 | +# ---------------------------------------------------------------------- |
| 71 | +# Option parsing |
| 72 | + |
| 73 | +# Options |
| 74 | +shortopts=c:r:hvV |
| 75 | +longopts=change=,revision=,help,verbose,version |
| 76 | + |
| 77 | +# Default values |
| 78 | + |
| 79 | +if [ "$(uname)" = "Linux" ]; then |
| 80 | + args=$(getopt -o "$shortopts" --long "$longopts" -n "$program" -- $SV "$@") |
| 81 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 82 | + eval set -- "$args" |
| 83 | + sed="sed -r" |
| 84 | +else |
| 85 | + # Darwin, BSDs |
| 86 | + args=$(getopt -o$shortopts $SV $*) |
| 87 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 88 | + set -- $args |
| 89 | + sed="sed -E" |
| 90 | +fi |
| 91 | + |
| 92 | +while true ; do |
| 93 | + case "$1" in |
| 94 | + -c| --change) CHG="$2"; shift;; # the change made by revision ARG |
| 95 | + -r| --revision) REV="$2"; shift;; # the change made between revisions REV |
| 96 | + -h| --help) usage; exit;; # Show this help, then exit |
| 97 | + -v| --verbose) VERBOSE=1;; # Be more talkative |
| 98 | + -V| --version) version; exit;; # Show program version, then exit |
| 99 | + --) shift; break;; |
| 100 | + *) die "Internal error, inconsistent option specification: '$1'";; |
| 101 | + esac |
| 102 | + shift |
| 103 | +done |
| 104 | + |
| 105 | +# ---------------------------------------------------------------------- |
| 106 | +# The program itself |
| 107 | + |
| 108 | +if [ $# -lt 2 ]; then die "Expected patch name and file list on the command line."; fi |
| 109 | +if [[ $1 =~ / ]]; then die "Expected a patch name, but the first argument to $program seems to be a file path: '$1'"; fi |
| 110 | + |
| 111 | +name=$1; shift; |
| 112 | + |
| 113 | +patchfile=$progdir/../../patches/$(date +%Y-%m-%d)-$name.patch |
| 114 | +svn diff ${CHG:+ -c $CHG} ${REV:+ -r $REV} "$@" > $patchfile |
| 115 | +less $patchfile |
| 116 | +echo "" |
| 117 | +echo "" |
| 118 | +echo "Patch is in $patchfile." |
0 commit comments