diff --git a/bin/mkpatch b/bin/mkpatch new file mode 100755 index 000000000..facf3059d --- /dev/null +++ b/bin/mkpatch @@ -0,0 +1,118 @@ +#!/bin/bash + +version=0.10 +program=${0##*/} +progdir=${0%/*} +if [ "$progdir" = "$program" ]; then progdir="."; fi + +# ---------------------------------------------------------------------- +function usage() { + cat < + +COPYRIGHT + Copyright 2013 Henrik Levkowetz. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at + your option) any later version. There is NO WARRANTY; not even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the GNU General Public License for more details. + +EOF + +} + +# ---------------------------------------------------------------------- +function die() { + echo -e "\n$program: error: $*" > /dev/stderr + exit 1 +} + +function note() { + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi +} + +# ---------------------------------------------------------------------- +function version() { + echo -e "$program $version" +} + +# ---------------------------------------------------------------------- +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR + + +# ---------------------------------------------------------------------- +# Option parsing + +# Options +shortopts=c:r:hvV +longopts=change=,revision=,help,verbose,version + +# Default values + +if [ "$(uname)" = "Linux" ]; then + args=$(getopt -o "$shortopts" --long "$longopts" -n "$program" -- $SV "$@") + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi + eval set -- "$args" + sed="sed -r" +else + # Darwin, BSDs + args=$(getopt -o$shortopts $SV $*) + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi + set -- $args + sed="sed -E" +fi + +while true ; do + case "$1" in + -c| --change) CHG="$2"; shift;; # the change made by revision ARG + -r| --revision) REV="$2"; shift;; # the change made between revisions REV + -h| --help) usage; exit;; # Show this help, then exit + -v| --verbose) VERBOSE=1;; # Be more talkative + -V| --version) version; exit;; # Show program version, then exit + --) shift; break;; + *) die "Internal error, inconsistent option specification: '$1'";; + esac + shift +done + +# ---------------------------------------------------------------------- +# The program itself + +if [ $# -lt 2 ]; then die "Expected patch name and file list on the command line."; fi +if [[ $1 =~ / ]]; then die "Expected a patch name, but the first argument to $program seems to be a file path: '$1'"; fi + +name=$1; shift; + +patchfile=$progdir/../../patches/$(date +%Y-%m-%d)-$name.patch +svn diff ${CHG:+ -c $CHG} ${REV:+ -r $REV} "$@" > $patchfile +less $patchfile +echo "" +echo "" +echo "Patch is in $patchfile."