Updated the bin/mkpatch to use a --name switch, normalize the name to use '-' rather than '_', and give more feedback.

- Legacy-Id: 18068
This commit is contained in:
Henrik Levkowetz 2020-06-26 15:23:52 +00:00
parent 3a76e4a935
commit 3c1c09c54a

View file

@ -1,4 +1,5 @@
#!/bin/bash
# -*- indent-with-tabs: 1 -*-
version=0.10
program=${0##*/}
@ -9,15 +10,15 @@ 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
$program - given a list of changed files, create a patch diff
SYNOPSIS
$program [OPTIONS] ARGS
$program [OPTIONS] PATHS
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.
Given 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
@ -29,8 +30,6 @@ EOF
fi
cat <<EOF
FILES
AUTHOR
Written by Henrik Levkowetz, <henrik@tools.ietf.org>
@ -71,8 +70,8 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
# Option parsing
# Options
shortopts=c:or:hvV
longopts=change=,overwrite,revision=,help,verbose,version
shortopts=c:n:or:hvV
longopts=change=,name=,overwrite,revision=,help,verbose,version
# Default values
@ -91,10 +90,11 @@ fi
while true ; do
case "$1" in
-c| --change) CHG="$2"; shift;; # the change made by revision ARG
-o| --overwrite) OVER=1;; # overwrite any existing patch file
-h| --help) usage; exit;; # Show this help, then exit
-v| --verbose) VERBOSE=1;; # Be more talkative
-c| --change) CHG="$2"; shift;; # Use the change made by revision ARG
-n| --name) NAME="$2"; shift;; # Patch name
-o| --overwrite) OVER=1;; # Overwrite any existing patch file
-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'";;
@ -105,13 +105,30 @@ done
# ----------------------------------------------------------------------
# The program itself
today=$(date +%s)
until=$(date -d 2020-10-01 +%s)
if [ $today -lt $until ]; then
echo -e "\n** Please note that the --name switch must now be used if you want to specify"\
"\n a name. If a changeset is given with the -c switch, the name can be"\
"\n autogenerated from the commit comment, though."\
"\n"
fi
if [ "$CHG" ]; then
name=$(echo $(svn log -c $CHG | sed -r -e '/^---/d' -e '/^r[0-9]+/d' -e '/^$/d' -e 's/Merged in \[[0-9]+\] from [^:]+..//' ) | sed -r -e 's/(.*)/\L\1/' -e 's/[^[:alnum:]]/-/g' -e 's/-+/-/g' -e's/-$//' | cut -c 1-40)
name="$name-c$CHG"
if [ "$NAME" ]; then
name="${NAME//_/-}-c$CHG"
else
name=$(echo $(svn log -c $CHG | sed -r -e '/^---/d' -e '/^r[0-9]+/d' -e '/^$/d' -e 's/Merged in \[[0-9]+\] from [^:]+..//' ) | sed -r -e 's/(.*)/\L\1/' -e 's/[^[:alnum:]]/-/g' -e 's/-+/-/g' -e's/-$//' | cut -c 1-40)
name="$name-c$CHG"
fi
else
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;
if [ "$NAME" ]; then
if [ $# -lt 1 ]; then die "Expected file list on the command line."; fi
name="${NAME//_/-}"
else
die "Please use the -n switch to provide a patch name"
fi
fi
patchfile=$progdir/../../patches/$(date +%Y-%m-%d)-$name.patch