diff options
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | quilt/fork.in | 113 | ||||
-rw-r--r-- | scripts/patchfns.in | 43 |
3 files changed, 158 insertions, 1 deletions
diff --git a/Makefile.in b/Makefile.in index 8c440a4..2545112 100644 --- a/Makefile.in +++ b/Makefile.in @@ -56,7 +56,8 @@ SRC += $(BIN_SRC:%=bin/%) DIRT += $(BIN_IN:%=bin/%) QUILT_IN := add applied delete diff files import new next patches \ - pop previous push refresh remove series setup top unapplied + pop previous push refresh remove series setup top unapplied \ + fork QUILT_SRC := $(QUILT_IN:%=%.in) QUILT := $(QUILT_IN) diff --git a/quilt/fork.in b/quilt/fork.in new file mode 100644 index 0000000..462676f --- /dev/null +++ b/quilt/fork.in @@ -0,0 +1,113 @@ +#! @BASH@ + +# This script is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# See the COPYING and AUTHORS files for more details. + +# Read in library functions +if [ "$(type -t patch_file_name)" != function ] +then + if ! [ -r @SCRIPTS@/patchfns ] + then + echo "Cannot read library @SCRIPTS@/patchfns" >&2 + exit 1 + fi + . @SCRIPTS@/patchfns +fi + +usage() +{ + echo $"Usage: quilt fork [new_name]" + if [ x$1 = x-h ] + then + echo $" +Fork the topmost patch. If new_name is missing, the name of the +forked patch will be the current patch name, followed by \"-2\". If the +If the patch name already ends in a dash-and-number, the number is +further incremented (e.g., patch.diff, patch-2.diff). The actual patch +is only created when \"quilt refresh\" is run. +" + exit 0 + else + exit 1 + fi +} + +options=`getopt -o h -- "$@"` + +if [ $? -ne 0 ] +then + usage +fi + +eval set -- "$options" + +while true +do + case "$1" in + -h) + usage -h ;; + --) + shift + break ;; + esac +done + +if [ $# -gt 1 ] +then + usage +fi + +top="$(top_patch)" +if [ -z "$top" ] +then + echo $"No patches applied" >&2 + exit 1 +fi +top_file_name="$(patch_file_name $top)" + +if [ $# -eq 1 ] +then + patch_file="$1" +else + set -- $(echo "$top" \ + | @SED@ -e 's: :\ :g' -e 's:-\([0-9]\+\)$: \1:') + if [ $# -eq 1 ]; then + patch_file="$1-2" + else + patch_file="$1-$[$2+1]" + fi + ext="$(echo $top_file_name \ + | @SED@ -e '\:\.\(diff\?\|patch\)\(\.gz\|\.bz2\|\)$:!d' \ + -e 's:.*\(\.\(diff\?\|patch\)\(\.gz\|\.bz2\|\)\)$:\1:')" + patch_file="$patch_file$ext" +fi + +patch_file=$(echo $patch_file | @SED@ -e 's/^'"$(quote_bre $P)"'patches\///') +patch=$(stripit $patch_file) +pc_dir=".pc/$patch" + +if patch_in_series $patch || \ + [ -d "$pc_dir" ] || \ + [ -e "patches/$patch_file" ] +then + echo $"Patch $patch exists already, please choose a new name" + exit 1 +fi + +if ! rename_in_db "$top" "$patch" || \ + ! rename_in_series "$top" "$patch_file" || \ + ! mv ".pc/$top" $pc_dir +then + echo $"Fork of $top_file_name to $patch_file failed" >&2 + exit 1 +fi + +echo $"Fork of $top_file_name created as $(patch_file_name $patch)" + +### Local Variables: +### mode: shell-script +### End: +# vim:filetype=sh diff --git a/scripts/patchfns.in b/scripts/patchfns.in index f16ad4e..1aab136 100644 --- a/scripts/patchfns.in +++ b/scripts/patchfns.in @@ -217,6 +217,28 @@ remove_from_series() fi } +rename_in_series() +{ + local from=$1 to=$2 + + tmpfile=$(gen_tempfile) || return 1 + /usr/bin/gawk ' + /^'"$(quote_re $from)"'(|\.patch|\.diff?)(|\.gz|\.bz2)([ \t]|$)/ \ + { sub(/'"$(quote_re $from)(|\.patch|\.diff?)(|\.gz|\.bz2)"'/, + "'"${to//\"/\\\"}"'") + print + good=1 } + END { exit(! good) } + ' $SERIES > $tmpfile + if [ $? -eq 0 ] + then + mv -f $tmpfile $SERIES + else + rm -f $tmpfile + return 1 + fi +} + pc_file_name() { while [ $# -gt 0 ] @@ -465,6 +487,27 @@ remove_from_db() fi } +rename_in_db() +{ + local from=$1 to=$2 + local tmpfile + tmpfile=$(gen_tempfile) || return 1 + /usr/bin/gawk ' + /^'"$(quote_re $from)"'$/ \ + { sub(/'"$(quote_re $from)"'/, "'"${to//\"/\\\"}"'") + print + good=1 } + END { exit(! good) } + ' $DB > $tmpfile + if [ $? -eq 0 ] + then + mv -f $tmpfile $DB + else + rm -f $tmpfile + return 1 + fi +} + stripit() { if [ -n "$1" ] |