Utility script to easily create an appropriately named patch file.
- Legacy-Id: 7195
This commit is contained in:
parent
fd5aac4583
commit
aede330b7e
118
bin/mkpatch
Executable file
118
bin/mkpatch
Executable file
|
@ -0,0 +1,118 @@
|
|||
#!/bin/bash
|
||||
|
||||
version=0.10
|
||||
program=${0##*/}
|
||||
progdir=${0%/*}
|
||||
if [ "$progdir" = "$program" ]; then progdir="."; fi
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
NAME
|
||||
$program - given a patch name and a list of files, create a patch diff
|
||||
|
||||
SYNOPSIS
|
||||
$program [OPTIONS] ARGS
|
||||
|
||||
DESCRIPTION
|
||||
Given a patch name and a list of changed file, run svn diff to create
|
||||
a patch suitable for the patch command, named with the current date
|
||||
and the given patch name. Place this in the local patch directory.
|
||||
|
||||
|
||||
EOF
|
||||
echo -e "OPTIONS"
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
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/'
|
||||
else
|
||||
egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /'
|
||||
fi
|
||||
cat <<EOF
|
||||
|
||||
FILES
|
||||
|
||||
AUTHOR
|
||||
Written by Henrik Levkowetz, <henrik@tools.ietf.org>
|
||||
|
||||
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."
|
Loading…
Reference in a new issue